{"id":1996,"library":"django-celery-results","title":"Django Celery Results","description":"Django Celery Results is an extension that enables you to store Celery task and group results using the Django ORM or Django's cache framework. It provides database models (TaskResult and GroupResult) to store task and group outcomes, which can then be queried like any other Django model. The library is actively maintained, with new versions typically released every few months to support the latest Django and Celery versions.","status":"active","version":"2.6.0","language":"en","source_language":"en","source_url":"https://github.com/celery/django-celery-results","tags":["django","celery","results","backend","task-queue","orm"],"install":[{"cmd":"pip install django-celery-results","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core task queue functionality.","package":"celery","optional":false},{"reason":"Provides the ORM and settings integration.","package":"Django","optional":false}],"imports":[{"note":"The PyPI package name uses a dash, but the Django app and Python import name uses underscores.","wrong":"INSTALLED_APPS = ['django-celery-results']","symbol":"django_celery_results","correct":"INSTALLED_APPS = ['django_celery_results']"},{"note":"Used for programmatic access to individual task results stored in the database.","symbol":"TaskResult","correct":"from django_celery_results.models import TaskResult"},{"note":"Used for programmatic access to Celery group results stored in the database.","symbol":"GroupResult","correct":"from django_celery_results.models import GroupResult"}],"quickstart":{"code":"# myproject/settings.py\nINSTALLED_APPS = [\n    # ... other apps\n    'django_celery_results',\n]\n\nCELERY_RESULT_BACKEND = 'django-db'\nCELERY_RESULT_EXTENDED = True # Recommended to store task args/kwargs/name\n\n# myproject/celery.py (or similar Celery app configuration)\nimport os\nfrom celery import Celery\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')\n\napp = Celery('myproject')\napp.config_from_object('django.conf:settings', namespace='CELERY')\napp.autodiscover_tasks()\n\n# myapp/tasks.py\nfrom celery import shared_task\n\n@shared_task\ndef add(x, y):\n    return x + y\n\n# To run and get result in Django shell:\n# from myapp.tasks import add\n# result = add.delay(4, 5)\n# print(result.get(timeout=10)) # Output: 9\n\n# Or to query from the DB:\n# from django_celery_results.models import TaskResult\n# task_db_result = TaskResult.objects.get(task_id=result.id)\n# print(task_db_result.status)\n# print(task_db_result.result)","lang":"python","description":"To quickly integrate `django-celery-results`, first add `django_celery_results` to your `INSTALLED_APPS` in `settings.py`. Then, configure Celery to use the Django ORM backend by setting `CELERY_RESULT_BACKEND = 'django-db'` and run Django migrations. It's also recommended to set `CELERY_RESULT_EXTENDED = True` to store full task metadata like arguments and names. A basic Celery app and a sample task are shown, along with how to retrieve results from the task object or directly from the database model."},"warnings":[{"fix":"Set `CELERY_RESULT_EXTENDED = True` in your Django `settings.py`.","message":"As of v2.4.0, the `TaskResult.task_name` field is no longer automatically populated by default due to a security concern. If your application relies on this field, you must explicitly set `CELERY_RESULT_EXTENDED = True` in your Django settings to store extended properties, which includes the task name, args, and kwargs.","severity":"breaking","affected_versions":">=2.4.0"},{"fix":"Upgrade Django to `3.2.25` or newer and Python to `3.6` or newer. Refer to the project's `pyproject.toml` or `setup.cfg` for exact dependency ranges.","message":"Support for older Django and Python versions has been dropped. v2.4.0 dropped Django 2.2 support, and v2.0.0 dropped support for Django < 2.2 and Python < 3.6. Ensure your environment meets the minimum requirements.","severity":"breaking","affected_versions":">=2.0.0, >=2.4.0"},{"fix":"Set `DJANGO_CELERY_RESULTS_TASK_ID_MAX_LENGTH=191` in your Django `settings.py` to shorten the `task_id` field length.","message":"When using MySQL, you might encounter `django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')` during migrations. This is due to indexing long string fields.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade `django-celery-results` to v2.3.0 or higher.","message":"The `default_app_config` attribute was deprecated in Django 3.1 and removed in Django 4.0. `django-celery-results` fixed this in v2.3.0. If you are on an older version of `django-celery-results` with Django 3.1+, you might see deprecation warnings.","severity":"deprecated","affected_versions":"<2.3.0 with Django >=3.1"},{"fix":"If a task relies on data committed within the current request/transaction, use `transaction.on_commit` to defer the task dispatch until after the transaction is successfully committed. Example: `from django.db import transaction; transaction.on_commit(lambda: my_task.delay(arg))`","message":"A common pitfall in Django and Celery integration is dispatching a task immediately that relies on database changes that haven't been committed yet. The Celery task might run before the database transaction is complete.","severity":"gotcha","affected_versions":"All"},{"fix":"Set `CELERY_RESULT_EXTENDED = True` in your Django `settings.py` to enable storing extended task properties like `args`, `kwargs`, and `task_name` in the `TaskResult` model.","message":"The default Celery configuration might not store detailed task arguments, keyword arguments, or other metadata. This can make debugging or re-running tasks difficult.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}