Fix iteration within iteration (#1427)

This commit is contained in:
Stefan Wójcik
2016-12-05 09:38:24 -05:00
committed by GitHub
parent 15714ef855
commit 4d0c092d9f
3 changed files with 92 additions and 12 deletions

View File

@@ -275,6 +275,8 @@ class BaseQuerySet(object):
except StopIteration:
return result
# If we were able to retrieve the 2nd doc, rewind the cursor and
# raise the MultipleObjectsReturned exception.
queryset.rewind()
message = u'%d items returned, instead of 1' % queryset.count()
raise queryset._document.MultipleObjectsReturned(message)