Using django models inside celery tasks
up vote
0
down vote
favorite
I have a use case, where I need to import some of my django
models inside the celery.py
file in a django-celery
standard project.
My project looks like follows:
|-- backend
| |-- backend
| | |-- __init__.py
| | |-- celery.py
| | |-- settings.py
| | |-- urls.py
| | `-- wsgi.py
| |-- bobbers
| | |-- __init__.py
| | |-- admin.py
| | |-- apps.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- manage.py
| |-- requirements.txt
All the contents of the celery related files (backend/backend/__init__.py
, and backend/backend/celery.py
) are exactly as indicated in the official docs.
But once I add the line import bobbers.models as bobber_models
to my celery.py
file, I get the infamous AppRegistryNotReady
error with the following stacktrace:
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 87, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 132, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Needless to say, if I remove the import, all goes well.
So how can I safely import django
models in the same file where I write my celery
tasks?
python django-celery
|
show 4 more comments
up vote
0
down vote
favorite
I have a use case, where I need to import some of my django
models inside the celery.py
file in a django-celery
standard project.
My project looks like follows:
|-- backend
| |-- backend
| | |-- __init__.py
| | |-- celery.py
| | |-- settings.py
| | |-- urls.py
| | `-- wsgi.py
| |-- bobbers
| | |-- __init__.py
| | |-- admin.py
| | |-- apps.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- manage.py
| |-- requirements.txt
All the contents of the celery related files (backend/backend/__init__.py
, and backend/backend/celery.py
) are exactly as indicated in the official docs.
But once I add the line import bobbers.models as bobber_models
to my celery.py
file, I get the infamous AppRegistryNotReady
error with the following stacktrace:
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 87, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 132, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Needless to say, if I remove the import, all goes well.
So how can I safely import django
models in the same file where I write my celery
tasks?
python django-celery
The question is why do you need to do this?
– Juan Ignacio Sánchez
Nov 10 at 15:27
Because my tasks do some heavy calculation and update parameters in the models. They also need model's attributes for the calculations
– bluesummers
Nov 10 at 15:40
Can you provide some high-level example? i mean, without code.
– Juan Ignacio Sánchez
Nov 10 at 16:13
I have a one to many relationship between two models, A and B. B has a numeric value. A has millions of B. I want to asynchronically update some parameter X of A that depends on the numeric values of B and the updating is a complex operation
– bluesummers
Nov 10 at 17:12
why don't you define a tasks.py as suggested in here: docs.celeryproject.org/en/latest/getting-started/…
– Juan Ignacio Sánchez
Nov 10 at 17:27
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a use case, where I need to import some of my django
models inside the celery.py
file in a django-celery
standard project.
My project looks like follows:
|-- backend
| |-- backend
| | |-- __init__.py
| | |-- celery.py
| | |-- settings.py
| | |-- urls.py
| | `-- wsgi.py
| |-- bobbers
| | |-- __init__.py
| | |-- admin.py
| | |-- apps.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- manage.py
| |-- requirements.txt
All the contents of the celery related files (backend/backend/__init__.py
, and backend/backend/celery.py
) are exactly as indicated in the official docs.
But once I add the line import bobbers.models as bobber_models
to my celery.py
file, I get the infamous AppRegistryNotReady
error with the following stacktrace:
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 87, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 132, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Needless to say, if I remove the import, all goes well.
So how can I safely import django
models in the same file where I write my celery
tasks?
python django-celery
I have a use case, where I need to import some of my django
models inside the celery.py
file in a django-celery
standard project.
My project looks like follows:
|-- backend
| |-- backend
| | |-- __init__.py
| | |-- celery.py
| | |-- settings.py
| | |-- urls.py
| | `-- wsgi.py
| |-- bobbers
| | |-- __init__.py
| | |-- admin.py
| | |-- apps.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- manage.py
| |-- requirements.txt
All the contents of the celery related files (backend/backend/__init__.py
, and backend/backend/celery.py
) are exactly as indicated in the official docs.
But once I add the line import bobbers.models as bobber_models
to my celery.py
file, I get the infamous AppRegistryNotReady
error with the following stacktrace:
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 87, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 132, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Needless to say, if I remove the import, all goes well.
So how can I safely import django
models in the same file where I write my celery
tasks?
python django-celery
python django-celery
asked Nov 10 at 15:21
bluesummers
2,01611943
2,01611943
The question is why do you need to do this?
– Juan Ignacio Sánchez
Nov 10 at 15:27
Because my tasks do some heavy calculation and update parameters in the models. They also need model's attributes for the calculations
– bluesummers
Nov 10 at 15:40
Can you provide some high-level example? i mean, without code.
– Juan Ignacio Sánchez
Nov 10 at 16:13
I have a one to many relationship between two models, A and B. B has a numeric value. A has millions of B. I want to asynchronically update some parameter X of A that depends on the numeric values of B and the updating is a complex operation
– bluesummers
Nov 10 at 17:12
why don't you define a tasks.py as suggested in here: docs.celeryproject.org/en/latest/getting-started/…
– Juan Ignacio Sánchez
Nov 10 at 17:27
|
show 4 more comments
The question is why do you need to do this?
– Juan Ignacio Sánchez
Nov 10 at 15:27
Because my tasks do some heavy calculation and update parameters in the models. They also need model's attributes for the calculations
– bluesummers
Nov 10 at 15:40
Can you provide some high-level example? i mean, without code.
– Juan Ignacio Sánchez
Nov 10 at 16:13
I have a one to many relationship between two models, A and B. B has a numeric value. A has millions of B. I want to asynchronically update some parameter X of A that depends on the numeric values of B and the updating is a complex operation
– bluesummers
Nov 10 at 17:12
why don't you define a tasks.py as suggested in here: docs.celeryproject.org/en/latest/getting-started/…
– Juan Ignacio Sánchez
Nov 10 at 17:27
The question is why do you need to do this?
– Juan Ignacio Sánchez
Nov 10 at 15:27
The question is why do you need to do this?
– Juan Ignacio Sánchez
Nov 10 at 15:27
Because my tasks do some heavy calculation and update parameters in the models. They also need model's attributes for the calculations
– bluesummers
Nov 10 at 15:40
Because my tasks do some heavy calculation and update parameters in the models. They also need model's attributes for the calculations
– bluesummers
Nov 10 at 15:40
Can you provide some high-level example? i mean, without code.
– Juan Ignacio Sánchez
Nov 10 at 16:13
Can you provide some high-level example? i mean, without code.
– Juan Ignacio Sánchez
Nov 10 at 16:13
I have a one to many relationship between two models, A and B. B has a numeric value. A has millions of B. I want to asynchronically update some parameter X of A that depends on the numeric values of B and the updating is a complex operation
– bluesummers
Nov 10 at 17:12
I have a one to many relationship between two models, A and B. B has a numeric value. A has millions of B. I want to asynchronically update some parameter X of A that depends on the numeric values of B and the updating is a complex operation
– bluesummers
Nov 10 at 17:12
why don't you define a tasks.py as suggested in here: docs.celeryproject.org/en/latest/getting-started/…
– Juan Ignacio Sánchez
Nov 10 at 17:27
why don't you define a tasks.py as suggested in here: docs.celeryproject.org/en/latest/getting-started/…
– Juan Ignacio Sánchez
Nov 10 at 17:27
|
show 4 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240364%2fusing-django-models-inside-celery-tasks%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The question is why do you need to do this?
– Juan Ignacio Sánchez
Nov 10 at 15:27
Because my tasks do some heavy calculation and update parameters in the models. They also need model's attributes for the calculations
– bluesummers
Nov 10 at 15:40
Can you provide some high-level example? i mean, without code.
– Juan Ignacio Sánchez
Nov 10 at 16:13
I have a one to many relationship between two models, A and B. B has a numeric value. A has millions of B. I want to asynchronically update some parameter X of A that depends on the numeric values of B and the updating is a complex operation
– bluesummers
Nov 10 at 17:12
why don't you define a tasks.py as suggested in here: docs.celeryproject.org/en/latest/getting-started/…
– Juan Ignacio Sánchez
Nov 10 at 17:27