1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[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
This commit is contained in:
Alex Gaynor 2010-06-22 18:09:08 +00:00
parent 33523c9f95
commit d6993c7dbb
2 changed files with 8 additions and 4 deletions

View File

@ -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 @@ class SQLCompiler(object):
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 = [

View File

@ -95,8 +95,7 @@ class MongoTestCase(TestCase):
]
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],