django-plans
django-plans copied to clipboard
Error expiring plans with Celery 5.0.0
I have got following import error with Celery 5.0.0:
File "/app/blenderhub/apps/accounts/management/commands/expire_plans.py", line 2, in <module>
from plans import tasks
File "/app/src/django-plans/plans/tasks.py", line 4, in <module>
from celery.task.base import periodic_task
ModuleNotFoundError: No module named 'celery.task'
Also, the Celery dependency should be optional, as django-plans
can now be used with management command instead of Celery.
Am facing this also! It's simple
from celery.decorators import periodic_task
If any one encounters this kind of error, the issue is quick easy to fix
- Solution 1 Disable autodiscover_tasks
#app.autodiscover_tasks(related_name="tasks")
This will ensure that celery does not scan for apps to find task to added, in this case the buggy plan.tasks won't be added also, because celery is not scanning for tasks in installed apps.
Though ensure that you set this variable
CELERY_IMPORTS = [ your tasks for celery to import ]
- Solution 2 Define which apps should be auto discored.
APPS_TO_FIND_TASKS = [ "app1", "app2, "app3", "app4"] # This can be handy if you have other thirdparty apps that you want to be automatically auto-discovered while rejecting others.
app.autodiscover_tasks(packages=APPS_TO_FIND_TASKS, related_name="tasks")
I have explained why it would be better to completely drop celery from the code base. https://github.com/django-getpaid/django-plans/pull/140#issuecomment-943681430
Probably it would be better to leave some text in the docs to guide user how to run the management commands or use celery or a hint to Celery related docs page.
The Celery dependency should be removed now.