Repository navigation
fix: raise QueryDefinitionError for related-model filters in update() and delete() - #1824
Merged
collerek merged 6 commits intoOct 12, 2026
Conversation
…elated-filter-1817 # Conflicts: # docs/releases.md
…elated-filter-1817 # Conflicts: # docs/releases.md
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will degrade performance by 25.75%ℹ️ 123 benchmarks have no flame graph
Performance Changes
Comparing |
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.
Fixes #1817
Summary
QuerySet.update()andQuerySet.delete()build a statement against the model's own table only. When the queryset was filtered or excluded by a related model's field (for examplefilter(category__name="x")), the join was silently dropped, so the statement either ignored the condition or failed with an invalid SQL statement.These methods now raise
QueryDefinitionErrornaming the offending filter, via a small private helper. Filters on the model's own fields are unaffected.Changes
ormar/queryset/queryset.py: guard inupdate()anddelete().tests/test_queries/test_queryset_level_methods.py: tests for filter and exclude on related fields in both methods.docs/releases.md: release note under Fixes.Checks run
ruff format --checkandruff check(ruff 0.16.10, matching the Makefile and poetry.lock) on the changed files: passmypy ormar tests/test_queries/test_queryset_level_methods.py --ignore-missing-imports: 4 errors, all pre-existing in untouchedormar/relations/*, none in changed filespytest tests/test_queries/test_queryset_level_methods.py: 18 passed