diff options
| author | Nilesh Kumar Pahari <nileshpahari@protonmail.com> | 2026-04-06 23:48:30 +0530 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-04-07 14:06:12 -0400 |
| commit | e27f23b268c520957384054fb236cfc303f95f51 (patch) | |
| tree | 8e51a4622acfba8827a0fad1553eb9f1051077fb /docs | |
| parent | 78a3ffbb4cec25ed003f16cf4b1aa0b4bcdc2590 (diff) | |
Fixed #36816 -- Allowed **kwargs in @task decorator.
The decorator was updated to accept **kwargs and forward them to
task_class, allowing additional parameters to be passed to custom
Task subclasses.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/tasks.txt | 30 | ||||
| -rw-r--r-- | docs/releases/6.1.txt | 4 |
2 files changed, 30 insertions, 4 deletions
diff --git a/docs/ref/tasks.txt b/docs/ref/tasks.txt index 99d8eb6a0a..1850c91cab 100644 --- a/docs/ref/tasks.txt +++ b/docs/ref/tasks.txt @@ -17,10 +17,13 @@ Task definition The ``task`` decorator ---------------------- -.. function:: task(*, priority=0, queue_name="default", backend="default", takes_context=False) +.. function:: task(*, priority=0, queue_name="default", backend="default", takes_context=False, **kwargs) - The ``@task`` decorator defines a :class:`Task` instance. This has the - following optional arguments: + The ``@task`` decorator defines a :class:`Task` instance. All keyword + arguments are passed directly to the backend's ``task_class`` (which + defaults to :class:`Task`). + + The following standard arguments are supported: * ``priority``: Sets the :attr:`~Task.priority` of the ``Task``. Defaults to 0. @@ -32,6 +35,18 @@ The ``task`` decorator :class:`TaskContext`. Defaults to ``False``. See :ref:`Task context <task-context>` for details. + Custom Task backends may define a custom ``task_class`` that accepts + additional arguments. These can be passed through the ``@task`` decorator:: + + @task(foo=5, bar=600) + def my_task(): + pass + + .. versionchanged:: 6.1 + + Support for passing arbitrary ``**kwargs`` to the ``@task`` decorator + is added. + If the defined ``Task`` is not valid according to the backend, :exc:`~django.tasks.exceptions.InvalidTask` is raised. @@ -75,6 +90,8 @@ The ``task`` decorator current time, a timezone-aware :class:`datetime <datetime.datetime>`, or ``None`` if not constrained. Defaults to ``None``. + This attribute can be set using :meth:`~Task.using`. + The backend must have :attr:`.supports_defer` set to ``True`` to use this feature. Otherwise, :exc:`~django.tasks.exceptions.InvalidTask` is raised. @@ -291,6 +308,13 @@ Base backend ``BaseTaskBackend`` is the parent class for all Task backends. + .. attribute:: BaseTaskBackend.task_class + + The :class:`~django.tasks.Task` subclass to use when creating tasks + with the :func:`~django.tasks.task` decorator. Defaults to + :class:`~django.tasks.Task`. Custom backends can override this to use + a custom ``Task`` subclass with additional attributes. + .. attribute:: BaseTaskBackend.options A dictionary of extra parameters for the Task backend. These are diff --git a/docs/releases/6.1.txt b/docs/releases/6.1.txt index 5dcdc9c50d..9c8aeea70c 100644 --- a/docs/releases/6.1.txt +++ b/docs/releases/6.1.txt @@ -348,7 +348,9 @@ Signals Tasks ~~~~~ -* ... +* The :func:`~django.tasks.task` decorator now accepts ``**kwargs``, which are + forwarded to the backend's + :attr:`~django.tasks.backends.base.BaseTaskBackend.task_class`. Templates ~~~~~~~~~ |
