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

   closes: #70056
   
   ## Problem
   
   A `DagRun` created pinned to a dag version (`bundle_version` set, 
`created_dag_version_id` populated) becomes unresolvable if that `dag_version` 
row is later deleted. The FK's `ondelete="set null"` clears 
`created_dag_version_id` while `bundle_version` stays set, so the pinned 
resolver in `DBDagBag._version_from_dag_run` returns `None` — it only falls 
back to the latest version for *unpinned* runs.
   
   `_start_queued_dagruns` then can't resolve the serialized DAG and hits `if 
not dag: log.error(...); continue`, so the run is neither started nor failed. 
It is re-selected and skipped on every scheduler loop **forever**, with no 
failure signal, no metric, and a misleading log (`DAG '...' not found in 
serialized_dag table` — the DAG *is* in `serialized_dag`; only the pinned 
version is gone). No timeout applies to a QUEUED run in this state; in 
production a run sat QUEUED for 8+ hours until manually cleared.
   
   ## Fix
   
   Fail the run explicitly when its pinned version can't be resolved, mirroring 
how the same function already handles a SCHEDULED task instance whose 
serialized DAG can't be found (that path sets the TI to `FAILED` and moves on). 
The error message now names the unresolved `created_dag_version_id` / 
`bundle_version`.
   
   This is option 1 from the issue. It doesn't change resolution for healthy or 
unpinned runs — only runs that are already unstartable get an explicit terminal 
state instead of being skipped indefinitely.
   
   ## Tests
   
   - `test_queued_dagrun_with_unresolvable_pinned_version_is_failed` — 
reproduces the pinned+NULL state and asserts the run reaches `FAILED` across 
repeated loops instead of staying `QUEUED`.
   - `test_queued_dagrun_without_bundle_version_falls_back_to_latest` — 
contrast: same NULL `created_dag_version_id` but unpinned still falls back to 
the latest serialized version and starts (`RUNNING`), so the fix doesn't touch 
that path.
   
   <!-- SPDX-License-Identifier: Apache-2.0 -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes (please specify the tool below)
   
   Generated-by: Claude Code following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


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