-
-
Notifications
You must be signed in to change notification settings - Fork 64
feat(filters): add RelationshipFilter for relationship-based queries #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cofin
wants to merge
9
commits into
litestar-org:main
Choose a base branch
from
cofin:feat/relationship-filters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Adds RelationshipFilter class enabling efficient filtering across SQLAlchemy relationships using EXISTS subqueries. This addresses two issues: - Issue litestar-org#364: Add StatementFilters for relationships & association patterns - Issue litestar-org#505: Fix MultiFilter with Many-to-Many generating incorrect SQL Features: - Support for one-to-many, many-to-one, many-to-many relationships - Nested relationship filtering (3+ levels) - negate parameter for NOT EXISTS queries - CollectionFilter auto-detection of relationship attributes - MultiFilter JSON API integration The implementation uses correlated EXISTS subqueries for optimal query performance with single database round-trip regardless of nesting depth.
Adds integration tests covering: - Many-to-many relationship filtering - Many-to-one relationship filtering - Negative filtering (NOT EXISTS) - CollectionFilter delegation to RelationshipFilter - MultiFilter JSON API integration Tests use existing uuid_test_session fixtures for consistency.
fd03568 to
ae4a4a1
Compare
Mock engines don't support actual database operations, so the RelationshipFilter tests cannot run meaningfully with them. This follows the same pattern used in test_filters.py and other integration tests.
Spanner doesn't support direct UNIQUE constraints, which are used in the UUID test models (IntegrationUUIDTag.name has unique=True).
Move Spanner and Oracle skips to dedicated fixtures that run before the uuid_test_session fixtures. This ensures the skip happens before schema creation, which fails on Spanner (UNIQUE constraints) and Oracle (schema isolation with xdist groups).
Add pytest_collection_modifyitems hook to skip relationship filter tests for Spanner and Oracle engines before fixtures are set up. This prevents errors from schema creation with UNIQUE constraints that Spanner doesn't support.
MySQL (asyncmy) has the same schema isolation issues with xdist groups as Oracle, causing "table doesn't exist" errors.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #639 +/- ##
==========================================
- Coverage 80.34% 80.31% -0.03%
==========================================
Files 87 87
Lines 6431 6534 +103
Branches 838 859 +21
==========================================
+ Hits 5167 5248 +81
- Misses 1000 1016 +16
- Partials 264 270 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Adds
RelationshipFilterclass enabling efficient filtering across SQLAlchemy relationships using EXISTS subqueries. This addresses:Features
negateparameter for NOT EXISTS queriesExample Usage
Test plan
Closes #364
Closes #505