From dee8d47a7e8a16f01aac504f92564c5a2e14023d Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Fri, 12 Nov 2021 21:06:18 +0100 Subject: [PATCH] Minor fixes related with recent merge for queryset_class --- docs/changelog.rst | 1 + mongoengine/document.py | 7 ++----- tests/queryset/test_queryset.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5c96e4f15..c49de79ff 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,7 @@ Development =========== - (Fill this out as you fix issues and develop your features). - EnumField improvements: now `choices` limits the values of an enum to allow +- Fix bug that prevented instance queryset from using custom queryset_class #2589 - Fix deepcopy of EmbeddedDocument #2202 - Fix error when using precision=0 with DecimalField #2535 - Add support for regex and whole word text search query #2568 diff --git a/mongoengine/document.py b/mongoengine/document.py index a3825d5d2..e56a9e7c2 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -583,11 +583,8 @@ def cascade_save(self, **kwargs): def _qs(self): """Return the default queryset corresponding to this document.""" if not hasattr(self, "__objects"): - queryset_class = self._meta.get("queryset_class") - if queryset_class is not None: - self.__objects = queryset_class(self.__class__, self._get_collection()) - else: - self.__objects = QuerySet(self.__class__, self._get_collection()) + queryset_class = self._meta.get("queryset_class", QuerySet) + self.__objects = queryset_class(self.__class__, self._get_collection()) return self.__objects @property diff --git a/tests/queryset/test_queryset.py b/tests/queryset/test_queryset.py index 427e13d10..aafa27711 100644 --- a/tests/queryset/test_queryset.py +++ b/tests/queryset/test_queryset.py @@ -3931,7 +3931,7 @@ class Post(Document): Post.drop_collection() assert isinstance(Post.objects, CustomQuerySet) - assert not Post.objects.delete() + assert Post.objects.delete() == 0 post = Post() post.save()