docs: clarify get/first/last MultipleMatches semantics#1678
Merged
Conversation
first/last (and their _or_none variants) always run with LIMIT 1 and never raise MultipleMatches — the docstrings claimed otherwise. get() only enforces the single-match contract when criteria are set; the no-criteria fallback returns the last row by pk and cannot raise MultipleMatches either. Updates the queryset and querysetproxy docstrings plus docs/queries/read.md to spell out this distinction. Refs #967
Merging this PR will not alter performance
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes |
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.
Summary
Fixes the internally inconsistent docstrings flagged in #967.
first()/last()(and their_or_nonevariants) always run withLIMIT 1via_fetch_single, soMultipleMatchescan never be raised — the docstrings claimed otherwise.get()enforces the single-match contract only when criteria are set (viafilter/excludeor args/kwargs). With no criteria it falls back to returning the last row by pk (LIMIT 1) and cannot raiseMultipleMatcheseither. The old wording ("first row meeting the criteria … MultipleMatches if more than 1 row") conflated these two modes.Docs-only change: updated docstrings in
ormar/queryset/queryset.pyandormar/relations/querysetproxy.py, plus the user-facingdocs/queries/read.mdsections forget/first/last.Closes #967
Test plan
make pre-commitmake coverage(100%, 653 passed)