django-plans icon indicating copy to clipboard operation
django-plans copied to clipboard

Error expiring plans with Celery 5.0.0

Open PetrDlouhy opened this issue 4 years ago • 3 comments

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.

PetrDlouhy avatar Sep 29 '20 08:09 PetrDlouhy

Am facing this also! It's simple

from celery.decorators import periodic_task

nmmapper avatar May 01 '21 19:05 nmmapper

If any one encounters this kind of error, the issue is quick easy to fix

  1. 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 ]

  1. 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")

nmmapper avatar Jun 28 '21 10:06 nmmapper

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.

Alir3z4 avatar Oct 14 '21 20:10 Alir3z4

The Celery dependency should be removed now.

PetrDlouhy avatar Jan 12 '23 14:01 PetrDlouhy