Repository navigation
Bound remaining single-row lookups with .limit(1) (#72699) - #72842
Merged
Merged
Conversation
* 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
requested review from
amoghrajesh,
ashb,
bugraoz93,
choo121600,
ephraimbuddy,
henry3260,
jason810496,
kaxil,
pierrejeambrun,
rawwar and
shubhamraj-git
as code owners
September 9, 2026 20:53
bbovenzi
approved these changes
Sep 9, 2026
jason810496
approved these changes
Sep 9, 2026
2 tasks done
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.
Backport of #72699 to
v3-3-testfor the 3.3.2 release.Bounds remaining single-row existence lookups with
.limit(1). Source files applied clean; the test import conflict resolved to addcapture_orm_selects(used) and dropconf_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?
Generated-by: Claude Code (Opus 4.8) following the guidelines