You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Mark failed" returns 500 when a run has task instances for a task no longer in the DAG #72338
After a few tasks were removed from a DAG, "Mark failed" on an older run returned HTTP 500:
File ".../api/common/mark_tasks.py", line 344, in set_dag_run_state_to_failed
pending_normal_tis = [ti for ti in pending_tis if not dag.task_dict[ti.task_id].is_teardown]
KeyError: '<task removed in a later DAG version>'
pending_tis is queried without restricting to the DAG's task ids, so it picks up TI rows for
tasks the new version no longer has, and the task_dict lookup blows up. running_tis, built a few
lines above, does apply that filter.
The asymmetry is still there on main, where the code has since been refactored into _set_dag_run_terminal_state: running_tis has TaskInstance.task_id.in_(task_ids), pending_tis does not, and the unguarded lookup is at line 300. So it survived that refactor.
How to reproduce
The crash needs a run holding a TI row for a task the resolved DAG version no longer defines.
The path that produced it here:
Remove a task from a DAG and let the dag-processor serialize a new version.
Clear an older run with run_on_latest_version=true. The run and its TIs end up on the new
version, while the removed task's instance row remains and is reset to NULL.
"Mark failed" on that run returns 500.
Clearing again does not help. SerializedDAG.clear selects every TI for the run regardless of
the version's task set, so it just resets the leftover rows and re-arms the error.
What you think should happen instead?
The two queries should be consistent, and a leftover task instance should be ignored rather than raise.
The scheduler already copes with this: once a run starts, verify_integrity marks such rows removed.
Operating System
No response
Deployment
None
Apache Airflow Provider(s)
No response
Versions of Apache Airflow Providers
No response
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
Suggested fix
Add TaskInstance.task_id.in_(task_ids) to the pending_tis query, mirroring running_tis.
Hi! @aeroyorch ...I’d be interested in helping investigate and add a regression test for this issue. I’ll first take a closer look at the existing implementation and contribution guidelines to make sure the fix aligns with the project’s expectations...
Activity
KHARSHAVARDHAN-eng commentedon Aug 31, 2026
Hi! @aeroyorch ...I’d be interested in helping investigate and add a regression test for this issue. I’ll first take a closer look at the existing implementation and contribution guidelines to make sure the fix aligns with the project’s expectations...
Fix mark-failed KeyError for removed-task TIs (#72338) (#72394)
[v3-3-test] Fix mark-failed KeyError for removed-task TIs (#72338) (#…
Fix mark-failed KeyError for removed-task TIs (apache#72338) (apache#…