Widen type hint for DagRun.get_task_instances / fetch_task_instances state parameter#67880
Conversation
The state parameter on DagRun.get_task_instances and DagRun.fetch_task_instances was annotated as Iterable[TaskInstanceState | None] | None, but the runtime handles a single TaskInstanceState value via an isinstance(state, str) short-circuit. Since TaskInstanceState(str, Enum) inherits from str, calling with state=TaskInstanceState.FAILED works at runtime but mypy/pyright flags it. Widen the annotation to TaskInstanceState | Iterable[TaskInstanceState | None] | None to match the actual runtime behaviour. Fixes apache#67653
|
Hi maintainer, this PR was merged without a milestone set.
|
Backport failed to create: v3-2-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker fb56cef v3-2-testThis should apply the commit to the v3-2-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
Fixes #67653
The
stateparameter onDagRun.get_task_instancesandDagRun.fetch_task_instanceswas annotated asIterable[TaskInstanceState | None] | None, but the runtime handles a singleTaskInstanceStatevalue via anisinstance(state, str)short-circuit. SinceTaskInstanceState(str, Enum)inherits fromstr, calling withstate=TaskInstanceState.FAILEDworks at runtime but mypy/pyright flags it.Fix: Widen the annotation to
TaskInstanceState | Iterable[TaskInstanceState | None] | Noneon both methods to match the actual runtime behaviour.