Skip to content

Chained queries break on same fields ($in followed by $eq). #135

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

Closed
anemitz opened this issue Sep 18, 2012 · 4 comments
Closed

Chained queries break on same fields ($in followed by $eq). #135

anemitz opened this issue Sep 18, 2012 · 4 comments
Milestone

Comments

@anemitz
Copy link
Member

anemitz commented Sep 18, 2012

        class A(Document):                                                                                                              
            pass                                                                                                                        

        class B(Document):                                                                                                              
            a = ReferenceField(A)                                                                                                       
            x = BooleanField()                                                                                                          

        a1 = A().save()                                                                                                                 
        a2 = A().save()                                                                                                                                                                                                                       

        # Works                                                  
        qs = B.objects.filter(a__in=[a1,a2], a=a1)                                                                                      

        # Doesn't work
        qs = B.objects.filter(a__in=[a1,a2], a=a1)                                                                                      
        qs = qs.filter(a=a1)   
  File "/Users/anemitz/Dropbox/projects/mongoengine/mongoengine/queryset.py", line 387, in _query
    self._mongo_query = self._query_obj.to_query(self._document)
  File "/Users/anemitz/Dropbox/projects/mongoengine/mongoengine/queryset.py", line 210, in to_query
    query = self.accept(SimplificationVisitor())
  File "/Users/anemitz/Dropbox/projects/mongoengine/mongoengine/queryset.py", line 261, in accept
    return visitor.visit_combination(self)
  File "/Users/anemitz/Dropbox/projects/mongoengine/mongoengine/queryset.py", line 80, in visit_combination
    return Q(**self._query_conjunction(queries))
  File "/Users/anemitz/Dropbox/projects/mongoengine/mongoengine/queryset.py", line 95, in _query_conjunction
    raise InvalidQueryError(msg + ', '.join(intersection))
InvalidQueryError: Duplicate query conditions: a

@rozza
Copy link
Contributor

rozza commented Sep 19, 2012

You define a and match against it multiple times - which is why the second example complains. Arguably, it should merge and make them all $in statements.

@anemitz
Copy link
Member Author

anemitz commented Sep 19, 2012

I'm patching it to do this: {$and: [{x: {$in:[1,2]}}, {x:1}]}

@rozza
Copy link
Contributor

rozza commented Sep 19, 2012

yeah that sounds better

rozza added a commit that referenced this issue Oct 1, 2012
@rozza
Copy link
Contributor

rozza commented Oct 1, 2012

Ok this passes for me..

@rozza rozza closed this as completed Oct 1, 2012
samuelclay added a commit to samuelclay/mongoengine that referenced this issue Oct 29, 2012
* 'master' of https://github.com/MongoEngine/mongoengine: (24 commits)
  Fixing py3 compat
  Added chaining regression test (MongoEngine#135)
  Updated test
  Unicode fix for repr (MongoEngine#133)
  Allow updates with match operators (MongoEngine#144)
  Unicode fix reverted but can have custom validator
  Fix loop
  Updated URLField
  Added Garry Polley to contributors list
  can now use AuthenticationBackends with permissions.
  Updates to the readme
  Added CONTRIBUTING.rst
  Updated docs thanks @mitar
  Moved injection of Exceptions to top level
  Fixed reload issue with ReferenceField where dbref=False (MongoEngine#138)
  Improved import cache
  Fixed objectId for DBRef
  Updated travis.yml
  Fix ReferenceField dbref = False
  Updated docs
  ...
dankantor pushed a commit to exfm/mongoengine that referenced this issue Dec 10, 2012
dankantor pushed a commit to exfm/mongoengine that referenced this issue Dec 10, 2012
samuelclay added a commit to samuelclay/mongoengine that referenced this issue Jan 28, 2013
* 'master' of github.com:samuelclay/mongoengine: (227 commits)
  Adding QuerySet(read_preference=pymongo.ReadPreference.X) and QuerySet().read_preference() method to override connection-level read_preference on a per-query basis.
  Fixing py3 compat
  Added chaining regression test (MongoEngine#135)
  Updated test
  Unicode fix for repr (MongoEngine#133)
  Allow updates with match operators (MongoEngine#144)
  Unicode fix reverted but can have custom validator
  Fix loop
  Updated URLField
  Added Garry Polley to contributors list
  can now use AuthenticationBackends with permissions.
  Updates to the readme
  Added CONTRIBUTING.rst
  Updated docs thanks @mitar
  Moved injection of Exceptions to top level
  Fixed reload issue with ReferenceField where dbref=False (MongoEngine#138)
  Improved import cache
  Fixed objectId for DBRef
  Updated travis.yml
  Fix ReferenceField dbref = False
  ...
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

2 participants