Skip to content

Bound remaining single-row lookups with .limit(1) (#72699) - #72842

Merged
vatsrahul1001 merged 1 commit into
v3-3-testfrom
backport-ff839573e9-v3-3-test
Sep 10, 2026
Merged

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

Conversation

@vatsrahul1001

Copy link
Copy Markdown
Contributor

Backport of #72699 to v3-3-test for the 3.3.2 release.

Bounds remaining single-row existence lookups with .limit(1). Source files applied clean; the test import conflict resolved to add capture_orm_selects (used) and drop conf_vars (unused on v3-3-test). Tests pass (incl. test_unfavorite_dag_existence_check_is_bounded).

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines

* Bound remaining single-row lookups with .limit(1)

Two more callers of ``session.scalars(...).first()`` /
``session.execute(select(...)).first()`` were still missing an explicit
``.limit(1)``. Because SQLAlchemy 2.0's ``Result.first()`` does not add
one (unlike the legacy ``Query.first``), each call sends every matching
row to the Python process and discards all but the first. The favorite
existence check is bounded to a single row per (dag_id, user_id) by the
schema, but the previous-TI lookup scans every earlier matching TI.

Introduced independently of #52325's migration: get_previous_task_instance
came in #59712, unfavorite_dag's existence probe in #51264. Same
anti-pattern as the four sites #72554 fixes; the tests reuse the
``capture_orm_selects`` helper that PR introduces.

* Also assert the returned row on the previous-TI regression test

(cherry picked from commit ff83957)
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.2 milestone Sep 10, 2026
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Sep 10, 2026
@vatsrahul1001
vatsrahul1001 merged commit dd7f63b into v3-3-test Sep 10, 2026
70 checks passed
@vatsrahul1001
vatsrahul1001 deleted the backport-ff839573e9-v3-3-test branch September 10, 2026 02:41
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.

4 participants