Repository navigation
base=DjangoTask keeps the task signature - #233
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since Celery 5.4 the Django fixup makes
DjangoTaskthe default task base, sodelay_on_commit/apply_async_on_commitare the idiomatic way to enqueue a task after the surrounding transaction commits. Typing that today meansbase=DjangoTask, which hits the genericbase: type[_T]overload and returns bareDjangoTask[..., Unknown]: the call signature is gone anddelay_on_commit(1)on astrparameter passes.This adds
base: type[DjangoTask[Any, Any]]overloads toshared_taskandCelery.task(bound and unbound) that returnDjangoTask[P, R], the same special-casing #227 did for the defaultTaskon a non-generic app. Python has no higher-kinded types, so this can't be done for an arbitrarybase=;DjangoTaskgets it because Celery ships it as a default base.Trade-off: a user subclass of
DjangoTaskpassed asbase=now also resolves toDjangoTask[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-argumentParamSpecrendering doesn't get in the way, plus one concrete task assertingdelay_on_commitreturnsAsyncResult[int].