Fix iteration on querysets.
If iteration of a queryset was interrupted (by a break, or a caught error), the next iterator would start from the second element as the cursor had already moved to the first. This is fixed by adding a rewind into the __iter__ method.
This commit is contained in:
@@ -567,7 +567,13 @@ class QuerySetTest(unittest.TestCase):
|
||||
people1 = [person for person in queryset]
|
||||
people2 = [person for person in queryset]
|
||||
|
||||
# Check that it still works even if iteration is interrupted.
|
||||
for person in queryset:
|
||||
break
|
||||
people3 = [person for person in queryset]
|
||||
|
||||
self.assertEqual(people1, people2)
|
||||
self.assertEqual(people1, people3)
|
||||
|
||||
def test_repr_iteration(self):
|
||||
"""Ensure that QuerySet __repr__ can handle loops
|
||||
|
||||
Reference in New Issue
Block a user