Browse Source

[Django] Ignore InterfaceError when closing database connection. Closes #2996

Ask Solem 9 years ago
parent
commit
597a6b1f33
1 changed files with 9 additions and 0 deletions
  1. 9 0
      celery/fixups/django.py

+ 9 - 0
celery/fixups/django.py

@@ -119,6 +119,13 @@ class DjangoWorkerFixup(object):
         self._cache = import_module('django.core.cache')
         self._settings = symbol_by_name('django.conf:settings')
 
+        try:
+            self.interface_errors = (
+                symbol_by_name('django.db.utils.InterfaceError'),
+            )
+        except (ImportError, AttributeError):
+            self._interface_errors = ()
+
         # Database-related exceptions.
         DatabaseError = symbol_by_name('django.db:DatabaseError')
         try:
@@ -269,6 +276,8 @@ class DjangoWorkerFixup(object):
         for close in funs:
             try:
                 close()
+            except self.interface_errors:
+                pass
             except self.database_errors as exc:
                 str_exc = str(exc)
                 if 'closed' not in str_exc and 'not connected' not in str_exc: