[Django] #36816: Allow **kwargs in @task decorator to support custom Task subclasses

20 views
Skip to first unread message

Django

unread,
Dec 21, 2025, 12:06:37 PM12/21/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-------------------------------------+-------------------------------------
Reporter: sharingan-no- | Type: Bug
kakashi |
Status: new | Component: Tasks
Version: 6.0 | Severity: Normal
Keywords: task | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Currently, the @task decorator accepts a fixed set of parameters and
passes only those to task_class:


Problem: When using a custom backend with a custom task_class that accepts
additional parameters (e.g., max_retries, timeout), there's no way to pass
those through the decorator.

{{{
def task(
function=None,
*,
priority=DEFAULT_TASK_PRIORITY,
queue_name=DEFAULT_TASK_QUEUE_NAME,
backend=DEFAULT_TASK_BACKEND_ALIAS,
takes_context=False,
):
# ...
return task_backends[backend].task_class(
priority=priority,
func=f,
queue_name=queue_name,
backend=backend,
takes_context=takes_context,
run_after=None
)

}}}


Proposed solution: Add **kwargs to the decorator signature and pass it
through to task_class:
{{{
def task(
function=None,
*,
priority=DEFAULT_TASK_PRIORITY,
queue_name=DEFAULT_TASK_QUEUE_NAME,
backend=DEFAULT_TASK_BACKEND_ALIAS,
takes_context=False,
**kwargs,
):
def wrapper(f):
return task_backends[backend].task_class(
priority=priority,
func=f,
queue_name=queue_name,
backend=backend,
takes_context=takes_context,
run_after=None,
**kwargs,
)

}}}

Use case example:

{{{
class MyTask(Task):
def __init__(self, *, max_retries=3, timeout=300, **kwargs):
super().__init__(**kwargs)
self.max_retries = max_retries
self.timeout = timeout

# With the proposed change:
@task(backend="my_backend", max_retries=5, timeout=600)
def my_task():
pass
}}}

This change is backwards compatible and aligns with Django's common
extensibility patterns.
--
Ticket URL: <https://code.djangoproject.com/ticket/36816>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 21, 2025, 1:38:06 PM12/21/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
------------------------+--------------------------------------
Reporter: Pietro | Owner: Kshitij
Type: Bug | Status: assigned
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------+--------------------------------------
Changes (by Kshitij):

* owner: (none) => Kshitij
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:1>

Django

unread,
Dec 21, 2025, 4:25:16 PM12/21/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+--------------------------------------
Reporter: Pietro | Owner: Kshitij
Type: New feature | Status: assigned
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Kshitij):

* type: Bug => New feature

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:2>

Django

unread,
Dec 21, 2025, 4:40:01 PM12/21/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+--------------------------------------
Reporter: Pietro | Owner: (none)
Type: New feature | Status: new
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Kshitij):

* owner: Kshitij => (none)
* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:3>

Django

unread,
Dec 21, 2025, 8:23:17 PM12/21/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+--------------------------------------
Reporter: Pietro | Owner: (none)
Type: New feature | Status: new
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by JaeHyuckSa):

* has_patch: 1 => 0

Django

unread,
Dec 22, 2025, 4:21:38 AM12/22/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+--------------------------------------
Reporter: Pietro | Owner: (none)
Type: New feature | Status: new
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Nilesh Pahari):

* cc: Nilesh Pahari (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:4>

Django

unread,
Dec 22, 2025, 3:28:57 PM12/22/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+--------------------------------------
Reporter: Pietro | Owner: (none)
Type: New feature | Status: new
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Jacob Walls):

* cc: Jake Howard (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:5>

Django

unread,
Dec 22, 2025, 4:36:32 PM12/22/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+------------------------------------
Reporter: Pietro | Owner: (none)
Type: New feature | Status: new
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Jake Howard):

* stage: Unreviewed => Accepted

Comment:

This sounds like a reasonable change to me.

As for the solution, my suggestion would be to drop all explicit
arguments, and only accept `**kwargs` in the `@task` decorator - instead
moving the defaults to the `Task` class itself. That also means that, for
whatever reason, a custom `Task` can override defaults.
--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:6>

Django

unread,
Dec 22, 2025, 4:59:54 PM12/22/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: 6.0
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Nilesh Pahari):

* owner: (none) => Nilesh Pahari
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:7>

Django

unread,
Dec 22, 2025, 5:04:52 PM12/22/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Jacob Walls):

* version: 6.0 => dev

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:8>

Django

unread,
Dec 24, 2025, 12:25:39 AM12/24/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Nilesh Pahari):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:9>

Django

unread,
Dec 24, 2025, 12:31:46 AM12/24/25
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Comment (by Nilesh Pahari):

PR: https://github.com/django/django/pull/20456
--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:10>

Django

unread,
Mar 3, 2026, 4:28:33 PMMar 3
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Jacob Walls):

* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:11>

Django

unread,
Mar 15, 2026, 11:40:53 PMMar 15
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+---------------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Kerollos Emad):

* needs_docs: 1 => 0
* stage: Accepted => Ready for checkin

Comment:

[https://github.com/django/django/pull/20917 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:12>

Django

unread,
Mar 16, 2026, 12:36:39 AMMar 16
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Kerollos Emad):

* stage: Ready for checkin => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:13>

Django

unread,
Mar 16, 2026, 8:32:56 AMMar 16
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Jacob Walls):

* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:14>

Django

unread,
Apr 4, 2026, 12:10:41 PM (4 days ago) Apr 4
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Nilesh Pahari):

* needs_docs: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:15>

Django

unread,
Apr 6, 2026, 1:35:15 PM (2 days ago) Apr 6
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Jacob Walls):

* needs_docs: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:16>

Django

unread,
Apr 6, 2026, 2:31:45 PM (2 days ago) Apr 6
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+-----------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by Nilesh Pahari):

* needs_docs: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:17>

Django

unread,
Apr 6, 2026, 2:54:47 PM (2 days ago) Apr 6
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+---------------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: task | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:18>

Django

unread,
Apr 7, 2026, 2:06:22 PM (yesterday) Apr 7
to django-...@googlegroups.com
#36816: Allow **kwargs in @task decorator to support custom Task subclasses
-----------------------------+---------------------------------------------
Reporter: Pietro | Owner: Nilesh Pahari
Type: New feature | Status: closed
Component: Tasks | Version: dev
Severity: Normal | Resolution: fixed
Keywords: task | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"e27f23b268c520957384054fb236cfc303f95f51" e27f23b]:
{{{#!CommitTicketReference repository=""
revision="e27f23b268c520957384054fb236cfc303f95f51"
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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36816#comment:19>
Reply all
Reply to author
Forward
0 new messages