From 4fe707a9b23a88128f6bf7cfa78a2c1d0caace57 Mon Sep 17 00:00:00 2001 From: Bastien Gerard Date: Thu, 20 Aug 2026 09:29:12 +0200 Subject: [PATCH] Remove deprecated Q and QCombination .empty method (in favor of bool) --- docs/changelog.rst | 2 ++ mongoengine/queryset/visitor.py | 21 --------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ca9ad6c80..d21df855e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,8 @@ Changes in 1.0.0 - Fix use of $geoNear or $collStats in aggregate #2493 - BREAKING CHANGE: Further to the deprecation warning, remove ability to use an unpacked list to `Queryset.aggregate(*pipeline)`, a plain list must be provided instead `Queryset.aggregate(pipeline)`, as it's closer to pymongo interface - BREAKING CHANGE: Further to the deprecation warning, remove `full_response` from `QuerySet.modify` as it wasn't supported with Pymongo 3+ +- BREAKING CHANGE: Remove the deprecated ``Q.empty`` and ``QNode.empty`` + properties. Use ``not query`` instead (or ``bool(query)`` for the inverse). - Fixed stacklevel of many warnings (to point places emitting the warning more accurately) - Add support for collation/hint/comment to delete/update and aggregate #2842 - BREAKING CHANGE: Remove LongField as it's equivalent to IntField since we drop support to Python2 long time ago (User should simply switch to IntField) #2309 diff --git a/mongoengine/queryset/visitor.py b/mongoengine/queryset/visitor.py index 9e26d4e83..e52d0dcd9 100644 --- a/mongoengine/queryset/visitor.py +++ b/mongoengine/queryset/visitor.py @@ -1,5 +1,4 @@ import copy -import warnings from mongoengine.errors import InvalidQueryError from mongoengine.queryset import transform @@ -7,11 +6,6 @@ __all__ = ("Q", "QNode") -def warn_empty_is_deprecated(): - msg = "'empty' property is deprecated in favour of using 'not bool(filter)'" - warnings.warn(msg, DeprecationWarning, stacklevel=2) - - class QNodeVisitor: """Base visitor class for visiting Q-object nodes in a query tree.""" @@ -108,11 +102,6 @@ def _combine(self, other, operation): return QCombination(operation, [self, other]) - @property - def empty(self): - warn_empty_is_deprecated() - return False - def __or__(self, other): return self._combine(other, self.OR) @@ -150,11 +139,6 @@ def accept(self, visitor): return visitor.visit_combination(self) - @property - def empty(self): - warn_empty_is_deprecated() - return not bool(self.children) - def __eq__(self, other): return ( self.__class__ == other.__class__ @@ -182,8 +166,3 @@ def __eq__(self, other): def accept(self, visitor): return visitor.visit_query(self) - - @property - def empty(self): - warn_empty_is_deprecated() - return not bool(self.query)