Skip to content

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
apache:mainfrom
ColtenOuO:scheduler-bulk-skip-timed-out-tis
Open

Replace per-TI session.merge() with a single UPDATE keyed on TI.id when a dagrun_timeout fires#67198
ColtenOuO wants to merge 1 commit into
apache:mainfrom
ColtenOuO:scheduler-bulk-skip-timed-out-tis

Conversation

@ColtenOuO
Copy link
Copy Markdown
Contributor

When dagrun_timeout fires, the scheduler loaded every unfinished TaskInstance, set its state in Python, and called session.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_(...)) and synchronize_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.

@ColtenOuO ColtenOuO requested review from XD-DENG and ashb as code owners May 19, 2026 17:19
@boring-cyborg boring-cyborg Bot added the area:Scheduler including HA (high availability) scheduler label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Scheduler including HA (high availability) scheduler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant