Validate operator arg types at decoration time in @task decorator#65041
Merged
kaxil merged 1 commit intoapache:mainfrom Apr 11, 2026
Merged
Validate operator arg types at decoration time in @task decorator#65041kaxil merged 1 commit intoapache:mainfrom
@task decorator#65041kaxil merged 1 commit intoapache:mainfrom
Conversation
Previously, passing wrong types to @task kwargs (e.g. `@task(task_id="fetch_{}".format)` or `@task(retries="three")`) was silently accepted at decoration time. Type errors only surfaced later when the task was invoked inside a DAG context, or not at all if the task was never used. Now validates all kwargs against BASEOPERATOR_ARGS_EXPECTED_TYPES in _TaskDecorator.__attrs_post_init__, catching type mismatches immediately at decoration time. Closes apache#65028
eladkal
approved these changes
Apr 11, 2026
Backport successfully created: v3-2-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
eladkal
pushed a commit
that referenced
this pull request
Apr 13, 2026
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.
Fixes #65028
Passing wrong types to
@taskkwargs (e.g.@task(task_id="fetch_{}".format)or@task(retries="three")) was silently accepted at decoration time. Type errors only surfaced later when the task was invoked inside a DAG context viavalidate_key()inBaseOperator.__init__, or not at all if the task was never called in a DAG.Now validates all kwargs against
BASEOPERATOR_ARGS_EXPECTED_TYPESin_TaskDecorator.__attrs_post_init__, catching type mismatches immediately when the decorator is applied.Design
The validation loop runs after
setdefaultpopulates the defaulttask_idfrom the function name (always a string), so only explicitly passed non-string values trigger it.Nonevalues are skipped (matching the existingvalidate_instance_argsbehavior).All
@task.*variants and.override(task_id=...)go through_TaskDecorator/attr.evolve()which re-runs__attrs_post_init__, so a single check covers all paths.Reuses the existing
BASEOPERATOR_ARGS_EXPECTED_TYPESdict rather than duplicating type definitions.