Skip to content

base=DjangoTask keeps the task signature - #233

Merged
kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
Parad0X:pdx/djangotask-base-overload
Sep 26, 2026
Merged

kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
Parad0X:pdx/djangotask-base-overload

Conversation

@Parad0X

@Parad0X Parad0X commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Since Celery 5.4 the Django fixup makes DjangoTask the default task base, so delay_on_commit / apply_async_on_commit are the idiomatic way to enqueue a task after the surrounding transaction commits. Typing that today means base=DjangoTask, which hits the generic base: type[_T] overload and returns bare DjangoTask[..., Unknown]: the call signature is gone and delay_on_commit(1) on a str parameter passes.

This adds base: type[DjangoTask[Any, Any]] overloads to shared_task and Celery.task (bound and unbound) that return DjangoTask[P, R], the same special-casing #227 did for the default Task on a non-generic app. Python has no higher-kinded types, so this can't be done for an arbitrary base=; DjangoTask gets it because Celery ships it as a default base.

Trade-off: a user subclass of DjangoTask passed as base= now also resolves to DjangoTask[P, R], so it gains the signature but loses attributes declared on the subclass. Overload order can't distinguish the two.

Tests use the func: Callable[P, R] pattern from #227 so mypy's named-argument ParamSpec rendering doesn't get in the way, plus one concrete task asserting delay_on_commit returns AsyncResult[int].

`shared_task(base=...)` and `Celery.task(base=...)` can only return the bare
base type, so `base=DjangoTask` lost the call signature and `delay_on_commit`
went unchecked. Add overloads for `type[DjangoTask[Any, Any]]` that return
`DjangoTask[P, R]`, mirroring the default-`Task` overloads.

@sbdchd sbdchd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sbdchd sbdchd added the automerge auto merge PRs using kodiak label Sep 26, 2026
@kodiakhq
kodiakhq Bot merged commit 6091528 into sbdchd:main Sep 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge auto merge PRs using kodiak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants