Skip to content
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

Unexpected behavior with & and multiple __in queries on the same field #227

Open
K900 opened this issue Jul 22, 2016 · 0 comments
Open

Unexpected behavior with & and multiple __in queries on the same field #227

K900 opened this issue Jul 22, 2016 · 0 comments

Comments

@K900
Copy link

K900 commented Jul 22, 2016

Hi! I'm building a long query by &-ing multiple smaller ones. It looks like when multiple __in queries on one field are combined with &, the resulting query combines all __in parameters into a single list, which produces incorrect results.

For example, running SomeModel.objects.filter(Q(some_id__in=[1]) & Q(some_id__in=[2])) should return nothing (and works correctly in upstream Django with an SQL database), but returns two objects with some_id's 1 and 2 in Django-Nonrel with MongoDB on the backend.

The SQL query is correct here: SELECT some_id, some_other_columns FROM some_table WHERE (some_table.some_id IN (1) AND some_table.some_id IN (2)).

The Mongo query, however, is (as logged by Mongo itself): "query" : {"find" : "some_collection", "filter" : {"some_id" : {"$in" : [1, 2]}}, "ntoreturn" : 21}.

Using Python 2.7.12, MongoDB 3.2.7, pip freeze:
Django==1.6.11
django-mongodb-engine==0.6.0
djangotoolbox==1.8.0
pymongo==2.8

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

No branches or pull requests

1 participant