Переглянути джерело

Use Django DB max age connection setting (fixes #4116) (#4292)

Marco Schweighauser 7 роки тому
батько
коміт
c086cfd27b
2 змінених файлів з 6 додано та 5 видалено
  1. 1 1
      celery/fixups/django.py
  2. 5 4
      t/unit/fixups/test_django.py

+ 1 - 1
celery/fixups/django.py

@@ -183,7 +183,7 @@ class DjangoWorkerFixup(object):
     def _close_database(self):
     def _close_database(self):
         for conn in self._db.connections.all():
         for conn in self._db.connections.all():
             try:
             try:
-                conn.close()
+                conn.close_if_unusable_or_obsolete()
             except self.interface_errors:
             except self.interface_errors:
                 pass
                 pass
             except self.DatabaseError as exc:
             except self.DatabaseError as exc:

+ 5 - 4
t/unit/fixups/test_django.py

@@ -216,11 +216,12 @@ class test_DjangoWorkerFixup(FixupCase):
             f._db.connections.all.side_effect = lambda: conns
             f._db.connections.all.side_effect = lambda: conns
 
 
             f._close_database()
             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):
             with pytest.raises(KeyError):
                 f._close_database()
                 f._close_database()