Skip to content

[v3-3-test] Reuse the explicit dag_run join on the previous-TI lookup (#72811) - #72944

Merged
vatsrahul1001 merged 1 commit into
v3-3-testfrom
backport-d076a57-v3-3-test
Sep 11, 2026
Merged

vatsrahul1001 merged 1 commit into
v3-3-testfrom
backport-d076a57-v3-3-test

Conversation

@github-actions

Copy link
Copy Markdown
Contributor
  • Reuse the explicit dag_run join on the previous-TI lookup

The previous-TI query in get_previous_task_instance explicitly joins
dag_run for the ORDER BY dag_run.logical_date and asked for a second
joinedload(TI.dag_run) for hydration. TaskInstance.dag_run is already
lazy="joined" on the mapper, so the eager-load actually attached a parallel
JOIN dag_run AS dag_run_1 next to the explicit join. Both joins pull the
same rows over the same FK pair.

Switch to contains_eager(TI.dag_run) so the eager-load reuses the explicit
join instead of adding a second one, and add a regression that fails when the
compiled SQL references dag_run more than once in the FROM clause.

  • Drop unused load_only import

  • Assert the eager-load claim by watching for stray dag_run SELECTs

  • Swap the stray-select capture for a request-level query count
    (cherry picked from commit d076a57)

Co-authored-by: Pierre Jeambrun [email protected]

…#72811)

* Reuse the explicit dag_run join on the previous-TI lookup

The previous-TI query in ``get_previous_task_instance`` explicitly joins
``dag_run`` for the ``ORDER BY dag_run.logical_date`` and asked for a second
``joinedload(TI.dag_run)`` for hydration. ``TaskInstance.dag_run`` is already
``lazy="joined"`` on the mapper, so the eager-load actually attached a parallel
``JOIN dag_run AS dag_run_1`` next to the explicit join. Both joins pull the
same rows over the same FK pair.

Switch to ``contains_eager(TI.dag_run)`` so the eager-load reuses the explicit
join instead of adding a second one, and add a regression that fails when the
compiled SQL references ``dag_run`` more than once in the FROM clause.

* Drop unused load_only import

* Assert the eager-load claim by watching for stray dag_run SELECTs

* Swap the stray-select capture for a request-level query count
(cherry picked from commit d076a57)

Co-authored-by: Pierre Jeambrun <[email protected]>
@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:task-sdk labels Sep 11, 2026
@vatsrahul1001
vatsrahul1001 marked this pull request as ready for review September 11, 2026 10:59
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.2 milestone Sep 11, 2026
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Sep 11, 2026
@vatsrahul1001
vatsrahul1001 merged commit 2dbf4cf into v3-3-test Sep 11, 2026
146 of 160 checks passed
@vatsrahul1001
vatsrahul1001 deleted the backport-d076a57-v3-3-test branch September 11, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants