-
Notifications
You must be signed in to change notification settings - Fork 30
Direct query lookup tests #426
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
Open
WaVEV
wants to merge
2
commits into
mongodb:main
Choose a base branch
from
WaVEV:direct-query-lookup-tests
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.
Open
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
9bf4025 to
804b0c0
Compare
timgraham
reviewed
Oct 27, 2025
tests/lookup_/tests.py
Outdated
Comment on lines
103
to
149
| def test_union_simple_conditions(self): | ||
| with self.assertNumQueries(1) as ctx: | ||
| list(Book.objects.filter(title="star wars").union(Book.objects.filter(isbn__in="1234"))) | ||
| self.assertAggregateQuery( | ||
| ctx.captured_queries[0]["sql"], | ||
| "lookup__book", | ||
| [ | ||
| {"$match": {"title": "star wars"}}, | ||
| {"$project": {"_id": 1, "title": 1, "isbn": 1}}, | ||
| { | ||
| "$unionWith": { | ||
| "coll": "lookup__book", | ||
| "pipeline": [ | ||
| {"$match": {"isbn": {"$in": ("1", "2", "3", "4")}}}, | ||
| {"$project": {"_id": 1, "title": 1, "isbn": 1}}, | ||
| ], | ||
| } | ||
| }, | ||
| {"$group": {"_id": {"_id": "$_id", "title": "$title", "isbn": "$isbn"}}}, | ||
| {"$addFields": {"_id": "$_id._id", "title": "$_id.title", "isbn": "$_id.isbn"}}, | ||
| ], | ||
| ) | ||
|
|
||
| def test_union_all_simple_conditions(self): | ||
| with self.assertNumQueries(1) as ctx: | ||
| list( | ||
| Book.objects.filter(title="star wars").union( | ||
| Book.objects.filter(isbn="1234"), all=True | ||
| ) | ||
| ) | ||
| self.assertAggregateQuery( | ||
| ctx.captured_queries[0]["sql"], | ||
| "lookup__book", | ||
| [ | ||
| {"$match": {"title": "star wars"}}, | ||
| {"$project": {"_id": 1, "title": 1, "isbn": 1}}, | ||
| { | ||
| "$unionWith": { | ||
| "coll": "lookup__book", | ||
| "pipeline": [ | ||
| {"$match": {"isbn": "1234"}}, | ||
| {"$project": {"_id": 1, "title": 1, "isbn": 1}}, | ||
| ], | ||
| } | ||
| }, | ||
| ], | ||
| ) |
Collaborator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these to queries_/test_qs_combinators.py to match the location of Django's tests for union(). Similarly, test_subquery_filter_constant may be more complicated than most lookup tests.
804b0c0 to
6ee279f
Compare
6ee279f to
1c6e93d
Compare
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.
This increases the test coverage for query refactor (#396).