From 2560145551099f15626b1a209ea6de8974817de4 Mon Sep 17 00:00:00 2001 From: Rached Ben Mustapha Date: Tue, 19 Oct 2010 22:23:08 +0000 Subject: [PATCH 1/2] add a failing test for the pagination bug --- tests/queryset.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/queryset.py b/tests/queryset.py index 6ca4174d..37fe7501 100644 --- a/tests/queryset.py +++ b/tests/queryset.py @@ -1377,6 +1377,23 @@ class QuerySetTest(unittest.TestCase): Post.drop_collection() + def test_call_after_limits_set(self): + """Ensure that re-filtering after slicing works + """ + class Post(Document): + title = StringField() + + Post.drop_collection() + + post1 = Post(title="Post 1") + post1.save() + post2 = Post(title="Post 2") + post2.save() + + posts = Post.objects.all()[0:1] + self.assertEqual(len(list(posts())), 1) + + Post.drop_collection() class QTest(unittest.TestCase): From 18baa2dd7a4e909169b694cb6ec36214c5a51506 Mon Sep 17 00:00:00 2001 From: Rached Ben Mustapha Date: Tue, 19 Oct 2010 22:40:36 +0000 Subject: [PATCH 2/2] fix calling a queryset after skip and limit have been set --- mongoengine/queryset.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 519dda03..f4849619 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -434,6 +434,12 @@ class QuerySet(object): if self._document._meta['ordering']: self.order_by(*self._document._meta['ordering']) + if self._limit is not None: + self._cursor_obj.limit(self._limit) + + if self._skip is not None: + self._cursor_obj.skip(self._skip) + return self._cursor_obj @classmethod