Skip to content

Commit 9671ca5

Browse files
committed
Merge pull request MongoEngine#1049 from DavidBord/fix-842
fix-MongoEngine#842: Fix ignored chained options
2 parents 222e929 + 5334ea3 commit 9671ca5

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changes in 0.10.1 - DEV
66
=======================
77
- Fix infinite recursion with CASCADE delete rules under specific conditions. #1046
88
- Fix CachedReferenceField bug when loading cached docs as DBRef but failing to save them. #1047
9+
- Fix ignored chained options #842
910

1011
Changes in 0.10.0
1112
=================

mongoengine/queryset/base.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,7 @@ def limit(self, n):
684684
:param n: the maximum number of objects to return
685685
"""
686686
queryset = self.clone()
687-
if n == 0:
688-
queryset._cursor.limit(1)
689-
else:
690-
queryset._cursor.limit(n)
691-
queryset._limit = n
687+
queryset._limit = n if n != 0 else 1
692688
# Return self to allow chaining
693689
return queryset
694690

@@ -699,7 +695,6 @@ def skip(self, n):
699695
:param n: the number of objects to skip before returning results
700696
"""
701697
queryset = self.clone()
702-
queryset._cursor.skip(n)
703698
queryset._skip = n
704699
return queryset
705700

@@ -717,7 +712,6 @@ def hint(self, index=None):
717712
.. versionadded:: 0.5
718713
"""
719714
queryset = self.clone()
720-
queryset._cursor.hint(index)
721715
queryset._hint = index
722716
return queryset
723717

tests/document/indexes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,11 @@ class BlogPost(Document):
577577
self.assertEqual(BlogPost.objects.hint('tags').count(), 10)
578578
else:
579579
def invalid_index():
580-
BlogPost.objects.hint('tags')
580+
BlogPost.objects.hint('tags').next()
581581
self.assertRaises(TypeError, invalid_index)
582582

583583
def invalid_index_2():
584-
return BlogPost.objects.hint(('tags', 1))
584+
return BlogPost.objects.hint(('tags', 1)).next()
585585
self.assertRaises(Exception, invalid_index_2)
586586

587587
def test_unique(self):

tests/queryset/queryset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def test_find(self):
188188
"[<Person: Person object>, <Person: Person object>]", "%s" % self.Person.objects[1:3])
189189
self.assertEqual(
190190
"[<Person: Person object>, <Person: Person object>]", "%s" % self.Person.objects[51:53])
191+
# Test only after limit
192+
self.assertEqual(self.Person.objects().limit(2).only('name')[0].age, None)
193+
# Test only after skip
194+
self.assertEqual(self.Person.objects().skip(2).only('name')[0].age, None)
191195

192196
def test_find_one(self):
193197
"""Ensure that a query using find_one returns a valid result.

0 commit comments

Comments
 (0)