From c086cfd27b9ec5d45e74dbcc6fd0d70926c3410a Mon Sep 17 00:00:00 2001 From: Marco Schweighauser Date: Sun, 1 Oct 2017 03:50:25 -0700 Subject: [PATCH] Use Django DB max age connection setting (fixes #4116) (#4292) --- celery/fixups/django.py | 2 +- t/unit/fixups/test_django.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/celery/fixups/django.py b/celery/fixups/django.py index 573ce47b858..008ac8473f3 100644 --- a/celery/fixups/django.py +++ b/celery/fixups/django.py @@ -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: diff --git a/t/unit/fixups/test_django.py b/t/unit/fixups/test_django.py index 7830497dd4a..023a04fbe97 100644 --- a/t/unit/fixups/test_django.py +++ b/t/unit/fixups/test_django.py @@ -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()