assertion failure when raw_query() with certain filters is followed by count() prior to evaluating QuerySet #112

Open
ablegrape opened this Issue Mar 15, 2012 · 2 comments

Comments

Projects
None yet
3 participants
@ablegrape

Versions: django_mongodb_engine: 0.4.0, MongoDB: 2.0.3, Python 2.7.1, MacOS 10.6.8.

This seems to be 100% reproducible with the following steps.

  1. Make any raw_query()
  2. filter() the results with an operator like __lt or __gt
  3. use count() on the resulting QuerySet
  4. try to evaluate the query set (e.g. with list(qs) or qs[subscript])

Boom! Assertion failure.

Here's an example (backslashes added to help GitHub display this nicely):

>>> qs=DataRecord.objects.raw_query({'some_field' : 430}).filter(other_field__lt=6)
>>> qs.count()
35
>>> qs[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mypath/nonrel/lib/python2.7/site-packages/django/db/models/query.py", line 190, in __getitem__
    return list(qs)[0]
  File "/mypath/nonrel/lib/python2.7/site-packages/django/db/models/query.py", line 84, in __len__
    self._result_cache.extend(self._iter)
  File "/mypath/nonrel/lib/python2.7/site-packages/django/db/models/query.py", line 275, in iterator
    for row in compiler.results_iter():
  File "/mypath/nonrel/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", line 229, in results_iter
    for entity in self.build_query(fields).fetch(low_mark, high_mark):
  File "/mypath/nonrel/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", line 289, in build_query
    query.add_filters(self.query.where)
  File "/mypath/nonrel/lib/python2.7/site-packages/django_mongodb_engine/compiler.py", line 159, in add_filters
    self.add_filters(child, query=subquery)
  File "/mypath/nonrel/lib/python2.7/site-packages/django_mongodb_engine/compiler.py", line 246, in add_filters
    assert all(key not in existing for key in lookup.keys()), [lookup, existing]
AssertionError: [{'$lt': 6}, {'$lt': 6}]

jonashaag added a commit that referenced this issue Mar 15, 2012

@jonashaag

This comment has been minimized.

Show comment
Hide comment
@jonashaag

jonashaag Mar 15, 2012

Contributor

Thanks for the report! I don't have time to fix this right now, but I added some tests that reproduce the issue (and another issue I stumbled upon).

Probably has something to do with mutable datastructures in the compiler.

Contributor

jonashaag commented Mar 15, 2012

Thanks for the report! I don't have time to fix this right now, but I added some tests that reproduce the issue (and another issue I stumbled upon).

Probably has something to do with mutable datastructures in the compiler.

@Alir3z4

This comment has been minimized.

Show comment
Hide comment
@Alir3z4

Alir3z4 Jun 28, 2014

@ablegrape Do you have a Decimal field defined on your model and you're trying to run filter on it?
I have the condition and I'm wondering yours is same to mine

Alir3z4 commented Jun 28, 2014

@ablegrape Do you have a Decimal field defined on your model and you're trying to run filter on it?
I have the condition and I'm wondering yours is same to mine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment