Skip to content

Commit

Permalink
Use Django DB max age connection setting (fixes celery#4116) (celery#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweigi authored and Omer Katz committed Oct 1, 2017
1 parent be55de6 commit c086cfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion celery/fixups/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def close_database(self, **kwargs):
def _close_database(self):
for conn in self._db.connections.all():
try:
conn.close()
conn.close_if_unusable_or_obsolete()
except self.interface_errors:
pass
except self.DatabaseError as exc:
Expand Down
9 changes: 5 additions & 4 deletions t/unit/fixups/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ def test__close_database(self):
f._db.connections.all.side_effect = lambda: conns

f._close_database()
conns[0].close.assert_called_with()
conns[1].close.assert_called_with()
conns[2].close.assert_called_with()
conns[0].close_if_unusable_or_obsolete.assert_called_with()
conns[1].close_if_unusable_or_obsolete.assert_called_with()
conns[2].close_if_unusable_or_obsolete.assert_called_with()

conns[1].close.side_effect = KeyError('omg')
conns[1].close_if_unusable_or_obsolete.side_effect = KeyError(
'omg')
with pytest.raises(KeyError):
f._close_database()

Expand Down

0 comments on commit c086cfd

Please sign in to comment.