Django 1.7rc3 and celery 3.13 - AppRegistryNotReady

This does not work for me

$> cat / etc / lsb-release
DISTRIB_ID = Ubuntu
DISTRIB_RELEASE = 12.04
DISTRIB_CODENAME = exact
DISTRIB_DESCRIPTION = "Ubuntu 12.04.2 LTS"

django 1.7rc3
celery 3.1.13
python 2.7

I'm trying to run

celery worker -A <project_name> 

and i get

 django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. 

The runerver command works fine, so I don’t think it is related to my settings?

 python manage.py runserver 0.0.0.0:8080 

I double checked celery.py and confirmed that it has the correct values ​​for the following lines:

 # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') app = Celery('proj') # Using a string here means the worker will not have to # pickle the object when using Windows. app.config_from_object('django.conf:settings') 

Is there anything else I should do?

+6
source share
3 answers

I found out that the reason this happened is because I had it in one of my .py tasks

 CURRENT_DOMAIN = Site.objects.get_current().domain 

Now I have stepped forward with

 CURRENT_DOMAIN = lambda: Site.objects.get_current().domain 

is currently waiting to find out if anyone on github wants to offer a better recommendation. https://github.com/celery/celery/issues/2227

will be updated if I receive it. If not, it will probably just perform a helper function that lazily returns the value I want.

Update
at the suggestion of the author of celery, I reworked my code, so I do not make this call at the module level.
He also addressed the problem, making sure django.setup () is called before importing the task modules
https://github.com/celery/celery/issues/2227

+1
source

Django 1.7 now requires a different initialization for stand-alone scripts. When working outside the context of manage.py you need to include:

 import django django.setup() 

Try adding it before app = Celery('proj') in the script.

+5
source

I see the same problem, but only with:

 CELERYBEAT_SCHEDULER='djcelery.schedulers.DatabaseScheduler' 

Do you have it? If I run it with the standard celery scheduler, it will load normally. But he cannot load it using the Django scheduler.

0
source

Source: https://habr.com/ru/post/974329/


All Articles