Skip to content

Commit

Permalink
[soc2010/query-refactor] Fixed Querysets in MongoDB with a limit of 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jun 22, 2010
1 parent 33523c9 commit d6993c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 7 additions & 2 deletions django/contrib/mongodb/compiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pymongo import ASCENDING, DESCENDING

from django.db.models.sql.datastructures import FullResultSet
from django.db.models.sql.datastructures import FullResultSet, EmptyResultSet


# TODO: ...
Expand Down Expand Up @@ -87,11 +87,16 @@ def build_query(self, aggregates=False):
if self.query.low_mark:
cursor = cursor.skip(self.query.low_mark)
if self.query.high_mark is not None:
if self.query.high_mark - self.query.low_mark == 0:
raise EmptyResultSet
cursor = cursor.limit(self.query.high_mark - self.query.low_mark)
return cursor

def results_iter(self):
query = self.build_query()
try:
query = self.build_query()
except EmptyResultSet:
return
fields = self.get_fields(aggregates=False)
if fields is None:
fields = [
Expand Down
3 changes: 1 addition & 2 deletions tests/regressiontests/mongodb/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def test_slicing(self):
]

for i in xrange(5):
# TODO: should be i, but Mongo falls over with limit(0)
for j in xrange(i+1, 5):
for j in xrange(i, 5):
self.assertQuerysetEqual(
Artist.objects.all()[i:j],
artists[i:j],
Expand Down

0 comments on commit d6993c7

Please sign in to comment.