kaxil opened a new pull request, #65041:
URL: https://github.com/apache/airflow/pull/65041
Fixes #65028
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 via `validate_key()` in `BaseOperator.__init__`,
or not at all if the task was never called in a DAG.
Now validates all kwargs against `BASEOPERATOR_ARGS_EXPECTED_TYPES` in
`_TaskDecorator.__attrs_post_init__`, catching type mismatches immediately when
the decorator is applied.
## Design
The validation loop runs after `setdefault` populates the default `task_id`
from the function name (always a string), so only explicitly passed non-string
values trigger it. `None` values are skipped (matching the existing
`validate_instance_args` behavior).
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_TYPES`](https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/bases/operator.py#L598-L632)
dict rather than duplicating type definitions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]