Browse Source

Django: Child processes must call django.setup if on Windows (Issue #2126)

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

+ 9 - 1
celery/fixups/django.py

@@ -136,9 +136,11 @@ class DjangoWorkerFixup(object):
     def validate_models(self):
         import django
         try:
-            django.setup()
+            django_setup = django.setup
         except AttributeError:
             pass
+        else:
+            django_setup()
         s = io.StringIO()
         try:
             from django.core.management.validation import get_validation_errors
@@ -166,6 +168,12 @@ class DjangoWorkerFixup(object):
         return self
 
     def on_worker_process_init(self, **kwargs):
+        # Child process must validate models again if on Windows,
+        # or if they were started using execv.
+        if os.environ.get('FORKED_BY_MULTIPROCESSING'):
+            self.validate_models()
+
+        # close connections:
         # the parent process may have established these,
         # so need to close them.