{"id":2005,"library":"django-tasks","title":"Django Tasks","description":"A backport of Django's built-in Tasks framework, `django-tasks` provides a robust way to run asynchronous background tasks within Django applications. As of version 0.12.0, it focuses on mirroring the upstream `django.tasks` package, with backends like DB and RQ now available as separate packages. It maintains an active release cadence, frequently updating to support new Django and Python versions.","status":"active","version":"0.12.0","language":"en","source_language":"en","source_url":"https://github.com/RealOrangeOne/django-tasks","tags":["django","tasks","background-tasks","async","queues"],"install":[{"cmd":"pip install django-tasks","lang":"bash","label":"Install core library"}],"dependencies":[{"reason":"Required for using the Database backend (if not already installed with core `django-tasks`).","package":"django-tasks-db","optional":true},{"reason":"Required for using the RQ backend (if not already installed with core `django-tasks`).","package":"django-tasks-rq","optional":true}],"imports":[{"note":"The decorator is imported from the top-level 'tasks' module, not 'django_tasks'.","wrong":"from django_tasks import task","symbol":"task","correct":"from tasks import task"},{"note":"Models are accessed via the 'tasks.models' path.","wrong":"from django_tasks.models import TaskResult","symbol":"TaskResult","correct":"from tasks.models import TaskResult"},{"note":"Used for manual synchronous task execution.","symbol":"run_task","correct":"from tasks import run_task"}],"quickstart":{"code":"import os\nfrom django.conf import settings\n\n# Minimal Django setup for demonstration\nif not settings.configured:\n    settings.configure(\n        INSTALLED_APPS=[\n            'django.contrib.auth',\n            'django.contrib.contenttypes',\n            'tasks' # Ensure 'tasks' is in INSTALLED_APPS\n        ],\n        DATABASES={\n            'default': {\n                'ENGINE': 'django.db.backends.sqlite3',\n                'NAME': ':memory:',\n            }\n        },\n        TASKS_BACKEND='tasks_db.backends.DatabaseBackend', # Or 'tasks_rq.backends.RQBackend'\n        USE_TZ=True\n    )\n\n# Ensure migrations are run for tasks_db if using it\n# In a real project, this would be part of `manage.py migrate`\nimport django\ndjango.setup()\n\n# This part assumes django-tasks-db is installed for the example\n# and that tasks.backends is configured.\n# For a true quickstart, you'd run `python manage.py makemigrations tasks_db && python manage.py migrate`\n\nfrom tasks import task\n\n@task\ndef greet_user(name):\n    print(f\"Hello, {name}!\")\n    return f\"Greeting for {name} completed.\"\n\n# Enqueue the task for asynchronous execution\nresult = greet_user.delay(\"World\")\nprint(f\"Task enqueued with ID: {result.pk}\")\n\n# To process the task (typically run by a worker process)\n# For local testing, you might manually run the task\n# from tasks import run_task\n# run_task(result.pk)\n\n# You can inspect the result object (needs refresh if worker is separate)\n# result.refresh_from_db()\n# print(f\"Task status: {result.status}\")\n# print(f\"Task result: {result.result}\")\n","lang":"python","description":"This quickstart demonstrates how to define a task using the `@task` decorator and enqueue it for asynchronous execution using `.delay()`. It includes a minimal Django configuration for testing, assuming the `django-tasks-db` backend is used and installed."},"warnings":[{"fix":"Install the new packages (e.g., `pip install django-tasks-db django-tasks-rq`) and update your `TASKS_BACKEND` setting in `settings.py` to point to the new backend paths (e.g., `'tasks_db.backends.DatabaseBackend'` or `'tasks_rq.backends.RQBackend'`).","message":"In version `0.12.0`, the Database and RQ backends were extracted into separate packages (`django-tasks-db` and `django-tasks-rq`). If you previously used these backends, `django-tasks` no longer includes them directly.","severity":"breaking","affected_versions":"0.12.0+"},{"fix":"Tasks should be enqueued directly using `.delay()`. If deferred execution within a transaction is required, you will need to implement custom transaction management logic or use a different mechanism.","message":"The `enqueue_on_commit` functionality was removed in version `0.10.0`.","severity":"breaking","affected_versions":"0.10.0+"},{"fix":"Update any code referencing `TaskResult.status == 'NEW'` to `TaskResult.status == 'READY'`. Access exceptions and tracebacks via the `task_result.errors` list (e.g., `task_result.errors[0].exception_class`, `task_result.errors[0].traceback`).","message":"In version `0.8.0`, the `TaskResult` status `NEW` was renamed to `READY` to better support retry functionality. Additionally, exceptions and tracebacks are now stored in a `.errors` list on the `TaskResult` model, rather than directly on `exception` and `traceback` attributes.","severity":"breaking","affected_versions":"0.8.0+"},{"fix":"Update any code referencing `TaskResult.status == 'completed'` to `TaskResult.status == 'succeeded'`.","message":"In version `0.6.0`, the `TaskResult` status `completed` was renamed to `succeeded`.","severity":"breaking","affected_versions":"0.6.0+"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}