Visitar URL original
fix: check exclude clauses before the unfiltered get() shortcut by zzoraemon043 · Pull Request #1865 · ormar-orm/ormar · GitHub
Skip to content

fix: check exclude clauses before the unfiltered get() shortcut - #1865

Merged
collerek merged 4 commits into
ormar-orm:masterfrom
zzoraemon043:fix/get-after-exclude
Oct 19, 2026
Merged

collerek merged 4 commits into
ormar-orm:masterfrom
zzoraemon043:fix/get-after-exclude

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

Fixes #1858

QuerySet.get() took the LIMIT 1 shortcut whenever filter_clauses was empty, so a queryset narrowed only by exclude() returned the last row instead of raising MultipleMatches. It now checks exclude_clauses too, like update() and delete() already do.

Added test_get_after_exclude_checks_all_matches to tests/test_queries/test_queryset_level_methods.py (fails before the change). pytest tests/test_queries passes on SQLite.

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 112 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 126 untouched benchmarks


Comparing zzoraemon043:fix/get-after-exclude (eb65b50) with master (1309e4b)

Open in CodSpeed

@zzoraemon043

Copy link
Copy Markdown
Contributor Author

test_inheritance_with_multi_relation was relying on the old behavior: exclude(co_owners__name="Joe") matches both Unicorn 2 and Unicorn 3 there, so get() used to just return the last one. Added filter(name="Unicorn 2") so it still checks the exclude on the m2m relation. Full suite passes locally on SQLite

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@collerek collerek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@collerek
collerek merged commit f3d4a62 into ormar-orm:master Oct 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QuerySet.get() after exclude() returns an arbitrary row instead of raising MultipleMatches

3 participants