deepujain opened a new pull request, #72394:
URL: https://github.com/apache/airflow/pull/72394

   ## 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
   - [x] `ruff check` and `ruff format --check` on changed files
   - [x] `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)
   - [ ] CI passes (ruff, mypy, pytest)
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (OpenAI Codex)
   
   Generated-by: OpenAI Codex following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   Fixes #72338


-- 
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]

Reply via email to