Browse Source

[Django] Set the default app so that runserver works

Ask Solem 11 years ago
parent
commit
ee3019386b
2 changed files with 7 additions and 1 deletions
  1. 5 1
      celery/app/base.py
  2. 2 0
      celery/fixups/django.py

+ 5 - 1
celery/app/base.py

@@ -24,7 +24,8 @@ from kombu.utils import cached_property, uuid
 
 from celery import platforms
 from celery._state import (
-    _task_stack, _tls, get_current_app, _register_app, get_current_worker_task,
+    _task_stack, _tls, get_current_app, set_default_app,
+    _register_app, get_current_worker_task,
 )
 from celery.exceptions import AlwaysEagerIgnored, ImproperlyConfigured
 from celery.five import items, values
@@ -150,6 +151,9 @@ class Celery(object):
     def set_current(self):
         _tls.current_app = self
 
+    def set_default(self):
+        set_default_app(self)
+
     def __enter__(self):
         return self
 

+ 2 - 0
celery/fixups/django.py

@@ -44,6 +44,8 @@ class DjangoFixup(object):
 
     def __init__(self, app):
         self.app = app
+        self.app.set_default()
+
         self.db_reuse_max = self.app.conf.get('CELERY_DB_REUSE_MAX', None)
         self._db = import_module('django.db')
         self._cache = import_module('django.core.cache')