Skip to content

Fix mark-failed KeyError for removed-task TIs (#72338) - #72394

Merged
pierrejeambrun merged 1 commit into
apache:mainfrom
deepujain:fix-72338-mark-failed-removed-task
Sep 7, 2026
Merged

pierrejeambrun merged 1 commit into
apache:mainfrom
deepujain:fix-72338-mark-failed-removed-task

Conversation

@deepujain

@deepujain deepujain commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Marking a DAG run failed could raise KeyError when the run still had task instance rows for tasks removed in a later DAG version. The pending_tis query did not filter to the current DAG's task ids, unlike the running_tis query, so lookups into dag.task_dict failed on orphaned rows. This change filters pending task instances the same way running ones are filtered.

Changes

  • airflow-core/src/airflow/api/common/mark_tasks.py -- add TaskInstance.task_id.in_(task_ids) to the pending task instance query in _set_dag_run_terminal_state.
  • airflow-core/tests/unit/api/common/test_mark_tasks.py -- add regression test for mark-failed with a leftover TI for a removed task.

Test plan

  • ruff check and ruff format --check on changed files
  • pytest airflow-core/tests/unit/api/common/test_mark_tasks.py::test_set_dag_run_state_to_failed_ignores_removed_task_tis (2 passed with existing test)
  • Current GitHub CI passes (ruff, mypy, pytest)
Was generative AI tooling used to co-author this PR?
  • Yes (OpenAI Codex)

Generated-by: OpenAI Codex following the guidelines

Fixes #72338

@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Sep 1, 2026
@deepujain
deepujain force-pushed the fix-72338-mark-failed-removed-task branch 3 times, most recently from eb43467 to 89868ee Compare September 2, 2026 14:55
@deepujain
deepujain force-pushed the fix-72338-mark-failed-removed-task branch 5 times, most recently from c4cb024 to 02bdd83 Compare September 3, 2026 07:45
@deepujain
deepujain force-pushed the fix-72338-mark-failed-removed-task branch from 02bdd83 to 84c7f26 Compare September 4, 2026 15:58

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks

@pierrejeambrun pierrejeambrun added this to the Airflow 3.3.2 milestone Sep 7, 2026
@pierrejeambrun
pierrejeambrun merged commit ddc423b into apache:main Sep 7, 2026
79 checks passed
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
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 Slack channel.

Status Branch Result
✅ v3-3-test PR Link

pierrejeambrun pushed a commit that referenced this pull request Sep 7, 2026
regarmukesh3g pushed a commit to regarmukesh3g/airflow that referenced this pull request Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Mark failed" returns 500 when a run has task instances for a task no longer in the DAG

3 participants