Repository navigation
Fix deadline never firing after non-deadline Dag edit - #68734
Conversation
|
Nice catch on the bug. Duplicating the data feels very heavy-handed, surely there's a better way? It looks like this whole issue is because Would it be a cleaner fix to calculate the hash early with |
ehab20011
left a comment
There was a problem hiding this comment.
hey ferruzi! thanks for the suggestion :) yea you're right, deferring cls(dag) past the branch decision is def a much cleaner approach. I've updated the PR to:
- Compute the hash early with
cls.hash(dag.data)instead of constructing the fullSerializedDagModel - Construct
cls(dag)at the top of theUPDATEbranch - In the
INSERTbranch, regenerateUUIDsand updatedag.databeforecls(dag), so the constructor picks up the right values naturally. Which then eliminates the 14-line post-hoc patching block (re-serializing, re-compressing, re-hashing internal attributes).
So yea and I think this should be good from here imo what do you think? all existing tests pass without modification when i ran them.
oh yea and one note, reused_deadline_data is still needed (not for the old UUIDs), but to hold the deadline definitions so we can create new DeadlineAlertModel records in the INSERT branch. Unless you think theres a better way
ferruzzi
left a comment
There was a problem hiding this comment.
Yeah, I think that looks better.
@sjyangkevin - Note this may cause a conflict with yours, but your deepcopy fix would go on top of this change
The structural issue was that cls(dag) was constructed before knowing which branch (skip / UPDATE / INSERT) we'd take. By deferring construction past the branch decision, each branch can prepare dag.data correctly before the constructor runs — eliminating the need for post-hoc patching of internal attributes. (cherry picked from commit 00ce83c) Co-authored-by: Ehab Abdalla <[email protected]>
The structural issue was that cls(dag) was constructed before knowing which branch (skip / UPDATE / INSERT) we'd take. By deferring construction past the branch decision, each branch can prepare dag.data correctly before the constructor runs — eliminating the need for post-hoc patching of internal attributes. (cherry picked from commit 00ce83c) Co-authored-by: Ehab Abdalla <[email protected]>
Description
This fixes the bug reported in #68732 by @katherine-wong7, where a deadline silently stops firing after any non-deadline DAG edit (e.g. adding a task). The root cause is that when
_try_reuse_deadline_uuidssuccessfully reuses existing deadline UUIDs, thedeadline_uuid_mappingis emptied (= {}). If the DAG hash still changes due to a non-deadline edit andwrite_dagenters the INSERT branch (newserialized_dagrow),_create_deadline_alert_recordsreceives an empty mapping and creates nothing. The new row ends up with deadline UUIDs in its JSON but zerodeadline_alertrows pointing to it so the materialization query at dag run creation finds nothing, and the deadline never fires.Where the problem was
airflow-core/src/airflow/models/serialized_dag.py, line 676 in thewrite_dagclassmethod:This emptying is fine when the hash matches (we short-circuit and skip writing), and fine for the UPDATE branch (same
serialized_dag.id, so existingdeadline_alertrows stay linked). But when the hash changes and the INSERT branch runs, the newserialized_dagrow has nodeadline_alertrows.Reproducing the bug locally
Wrote a test that mirrors the exact scenario from the issue — create a deadline-bearing DAG, add a dagrun (to force the INSERT branch), add a second task (non-deadline change), re-serialize, and assert the new
serialized_daghas a linkeddeadline_alert.Running this test without the fix fails with the exact error described in the issue:
The fix
Updated based on reviewer feedback: the structural issue was that
cls(dag)was constructed before knowing which branch (skip / UPDATE / INSERT) we'd take. By deferring construction past the branch decision, each branch can preparedag.datacorrectly before the constructor runs — eliminating the need for post-hoc patching of internal attributes.Changes to
write_daginairflow-core/src/airflow/models/serialized_dag.py:cls.hash(dag.data)instead ofcls(dag)— to decide which branch to take without constructing the full object.cls(dag)at the top of the branch. Reused UUIDs are already indag.data, so the constructor picks them up naturally.dag.databefore callingcls(dag), so the constructor serializes the correct data. This replaces the previous 14-line post-hoc patching block that manually re-serialized, re-compressed, and re-hashed internal attributes.The UPDATE branch needs no change — it updates the row in place (same
serialized_dag.id), so existingdeadline_alertrows remain correctly linked.Testing
Added three tests covering all branches where deadline reuse interacts with re-serialization:
test_non_deadline_edit_creates_deadline_alert_for_new_serdagserialized_daggets its owndeadline_alertrows, old version's alerts stay intacttest_non_deadline_edit_preserves_alert_in_update_branchtest_deadline_reuse_skips_write_when_hash_matcheswrite_dagreturnsFalse, alerts untouchedAll deadline tests pass (each runs in both raw and compressed serialization modes):
closes: #68732
Was generative AI tooling used to co-author this PR?