Skip to content

Commit d6993c7

Browse files
committed
[soc2010/query-refactor] Fixed Querysets in MongoDB with a limit of 0.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 33523c9 commit d6993c7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

django/contrib/mongodb/compiler.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pymongo import ASCENDING, DESCENDING
22

3-
from django.db.models.sql.datastructures import FullResultSet
3+
from django.db.models.sql.datastructures import FullResultSet, EmptyResultSet
44

55

66
# TODO: ...
@@ -87,11 +87,16 @@ def build_query(self, aggregates=False):
8787
if self.query.low_mark:
8888
cursor = cursor.skip(self.query.low_mark)
8989
if self.query.high_mark is not None:
90+
if self.query.high_mark - self.query.low_mark == 0:
91+
raise EmptyResultSet
9092
cursor = cursor.limit(self.query.high_mark - self.query.low_mark)
9193
return cursor
9294

9395
def results_iter(self):
94-
query = self.build_query()
96+
try:
97+
query = self.build_query()
98+
except EmptyResultSet:
99+
return
95100
fields = self.get_fields(aggregates=False)
96101
if fields is None:
97102
fields = [

tests/regressiontests/mongodb/tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def test_slicing(self):
9595
]
9696

9797
for i in xrange(5):
98-
# TODO: should be i, but Mongo falls over with limit(0)
99-
for j in xrange(i+1, 5):
98+
for j in xrange(i, 5):
10099
self.assertQuerysetEqual(
101100
Artist.objects.all()[i:j],
102101
artists[i:j],

0 commit comments

Comments
 (0)