Permalink
Browse files

[soc2010/query-refactor] Fixed Querysets in MongoDB with a limit of 0.

  • Loading branch information...
1 parent 33523c9 commit d6993c7dbb4ffef939e9061a701be2e442971d3b @alex alex committed Jun 22, 2010
Showing with 8 additions and 4 deletions.
  1. +7 −2 django/contrib/mongodb/compiler.py
  2. +1 −2 tests/regressiontests/mongodb/tests.py
@@ -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: ...
@@ -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 = [
@@ -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],

0 comments on commit d6993c7

Please sign in to comment.