You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "kaxil (via GitHub)" <gi...@apache.org> on 2026/04/11 01:12:16 UTC
[PR] Validate operator arg types at decoration time in ``@task`` decorator [airflow]
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Validate operator arg types at decoration time in ``@task`` decorator [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #65041:
URL: https://github.com/apache/airflow/pull/65041#issuecomment-4229306210
### Backport successfully created: v3-2-test
Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>✅</td>
<td>v3-2-test</td>
<td><a href="https://github.com/apache/airflow/pull/65050"><img src="https://img.shields.io/badge/PR-65050-blue" alt="PR Link"></a></td>
</tr>
</table>
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Validate operator arg types at decoration time in ``@task`` decorator [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil merged PR #65041:
URL: https://github.com/apache/airflow/pull/65041
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org