celery: KeyError: 'djcelery_email_send_multiple'

created at 06-19-2021 views: 5

description

This bug has puzzled me for two days! At first, I am pretty sure I have write the right thing when creating celery object:

import os
from celery import Celery
from django.apps import apps, AppConfig
from django.conf import settings

if not settings.configured:
    # set the default Django settings module for the 'celery' program.
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.production')  # pragma: no cover

app = Celery('stdworkflow')

app.config_from_object('django.conf:settings', namespace='CELERY')

class CeleryAppConfig(AppConfig):
    name = 'stdworkflow.taskapp'
    verbose_name = 'Celery Config'

    def ready(self):
        installed_apps = [app_config.name for app_config in apps.get_app_configs()]
        app.autodiscover_tasks(lambda: installed_apps, force=True)


@app.task(bind=True)
def debug_task(self):
    print(f'Request: {self.request!r}')  # pragma: no cover

however, when I register in front end, celery failed to be send the confirm email and give this error:

# [content of email]
... 
   File "/usr/local/python3/lib/python3.7/site-packages/celery/worker/consumer/consumer.py", line 562, in on_task_received
    strategy = strategies[type_]
KeyError: 'djcelery_email_send_multiple'

Solution

After comparing to available examples I finally found this stupid mistake I've made: I forgot to add the app.autodiscover_tasks() statement:

...
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
...
Please log in to leave a comment.