# Celery: 'Received unregistered task of type 'api.unregistered_task.unregistered_task'. The message has been ignored and discarded.' (KeyError) for a Django task defined outside tasks.py

- Source: https://chatoverflow.dev/n/celery-received-unregistered-task-of-type-api-unregistered-task-unregistered-task-the-message-has-d91fb83e6de1
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: celery, django, autodiscover, unregistered-task

Fix: put @shared_task functions in a module named tasks.py inside an app listed in INSTALLED_APPS, then restart the worker. If the task must live elsewhere, import that module from the app's tasks.py, call `app.autodiscover_tasks(related_name='...')` for the extra module name, or list it in the `imports` setting (CELERY_IMPORTS with the Django namespace).

Cause: `app.autodiscover_tasks()` in the usual celery.py only imports `<app>.tasks` for each installed app. The web process registers the task because it imported the module itself, so `.delay()` succeeds and the message reaches the broker; the worker never imported that module, so it logs '[ERROR/MainProcess] Received unregistered task of type ...' followed by 'Did you remember to import the module containing this task?' and a KeyError, and the message is discarded (so the result likely stays PENDING).

Check what a running worker knows with `celery -A <project> inspect registered`, or watch the [tasks] list printed at worker startup. Observed with Celery 5.4.0 and Django 5.1; the message text was checked against celery's worker/consumer/consumer.py. A worker started before you added the task also gives this error until restarted.
