Uh oh!
There was an error while loading. Please reload this page.
Fail queued DagRuns with an unresolvable pinned dag version - #70072
Fail queued DagRuns with an unresolvable pinned dag version #70072RehanAhmad25 wants to merge 4 commits into
Conversation
ephraimbuddy
left a comment
There was a problem hiding this comment.
How about changing the dagrun column to restrict like TI dag version column? Can you find out why we used set null. I can’t remember now but it seems wrong now
RehanAhmad25
commented
Jul 18, 2026
Yeah, I think we can change it, RESTRICT looks like the right call here. Dug through git blame on this. DagRun just never got the same follow-up. Looks like an oversight from that period rather than a deliberate choice, nothing in the PR discussion explains why DagRun should behave differently from TI here. I checked whether RESTRICT would actually be safe to add: the only place dag_version rows get deleted at all is delete_dag(), and it already deletes TaskInstance and DagRun rows before the DagModel cascade touches DagVersion (there's a comment in that function about doing this on purpose for TI's RESTRICT constraint). So DagRun would already be gone by the time the cascade fires, switching to RESTRICT shouldn't affect normal dag deletion at all, it'd only ever trigger in exactly the broken scenario this issue describes. I can add a migration for it, basically mirroring 0072 but for dag_run.created_dag_version_id, want me to add that to this PR or should it go separately? |
ephraimbuddy
commented
Jul 21, 2026
Yes. Let's add it to this PR |
26e940e to
ee23be4CompareRehanAhmad25
commented
Jul 22, 2026
@ephraimbuddy Completed the migration work discussed above and force-pushed this branch. A couple of local pre-push checks blocked the push at first, both unrelated to this PR, more on that below, so I bypassed them locally to get this up. What changed: added the migration, changing Why the force-push: I rebased onto current The local checks that blocked me: Could someone approve the workflows so CI can run on this? Happy to address anything it turns up. |
ee23be4 to
86bfc53CompareRehanAhmad25
commented
Aug 22, 2026
@ephraimbuddy Following up here since it's been about a month with no activity, apologies for the gap on my end too, had to sync up with a bunch of upstream changes. Since that last comment, I rebased again to catch up with main (a good chunk had landed since, including some new migrations), fixed the resulting conflicts, and this time everything came through clean, no CI-blocking issues locally, no need to bypass any checks. While I was at it, I also caught and fixed a real bug that surfaced from the rebase: turned out Whenever you get a chance, would appreciate a look, and if it needs another round of workflow approval to get CI running, happy to poke that too. No rush, just wanted to bump this since it's been sitting a while. |
Fail queued DagRuns with an unresolvable pinned dag version
closes: #70056
A DagRun pinned to a specific dag version (bundle_version + created_dag_version_id) can get stuck in QUEUED forever if the pinned version row is later deleted. The FK is ON DELETE SET NULL, so created_dag_version_id becomes NULL while bundle_version stays set, and _version_from_dag_run only falls back to the latest versionwhen bundle_version is unset. The run is neither started nor failed, logged and skipped on every scheduler loop indefinitely.
This detects that specific, permanently-unresolvable case (pinned version deleted) and fails the run explicitly via set_state(), which correctly updates end_date along with the state transition. Other reasons get_dag_for_run can return None (e.g. an unpinned run whose version hasn't parsed yet) are left untouched, since those can still resolve on a later loop and shouldn't be failed outright.
A second test confirms that scoping: an unpinned run with no resolvable version yet stays QUEUED rather than being failed.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude (Anthropic) following the guidelines