Replace per-TI session.merge() with a single UPDATE keyed on TI.id when a dagrun_timeout fires - #67198
Open
ColtenOuO wants to merge 1 commit into
Open
Replace per-TI session.merge() with a single UPDATE keyed on TI.id when a dagrun_timeout fires#67198ColtenOuO wants to merge 1 commit into
ColtenOuO wants to merge 1 commit into
Conversation
…en a dagrun_timeout fires.
potiuk
marked this pull request as draft
July 2, 2026 18:44
potiuk
marked this pull request as ready for review
July 2, 2026 22:14
steveahnahn
approved these changes
Jul 7, 2026
steveahnahn
left a comment
Contributor
There was a problem hiding this comment.
Nice cleanup. The per-row session.merge() was redundant since these TIs are already attached to the session.
I checked the path on main and the behavior looks preserved
Contributor
Author
|
cc @jason810496, @ashb Whenever you have a moment, could you please take a look at this PR >< |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
dagrun_timeoutfires, the scheduler loaded every unfinished TaskInstance, set its state in Python, and calledsession.merge()per row. The TIs are already attached to the session, so the merge is redundant and the ORM unit-of-work flush emits one UPDATE per row — N statements for N tasks.This PR replaces the loop with a single
update(TI).where(TI.id.in_(...))andsynchronize_session="fetch", matching the bulk pattern already used at scheduler_job_runner.py:798-803 and aligning with the AGENTS.md rule to batch scheduler DELETE/UPDATE (#66908).Behaviour is unchanged.