From 3194a37fcb9654458373ffe0a738038003f7e521 Mon Sep 17 00:00:00 2001 From: Tom Floyer Date: Sat, 8 Dec 2018 22:14:43 +0300 Subject: [PATCH] Reset cursor object after .count() This change fixes incorrect result of .only() method of QuerySet instance after using .count(). --- mongoengine/queryset/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index 6c36d984..862a1826 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -396,7 +396,9 @@ class BaseQuerySet(object): """ if self._limit == 0 and with_limit_and_skip is False or self._none: return 0 - return self._cursor.count(with_limit_and_skip=with_limit_and_skip) + count = self._cursor.count(with_limit_and_skip=with_limit_and_skip) + self._cursor_obj = None + return count def delete(self, write_concern=None, _from_doc_delete=False, cascade_refs=None):