Skip to content

Commit 830bc08

Browse files
WaVEVtimgraham
authored andcommitted
fix count in negated expressions
1 parent 0eccf7d commit 830bc08

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

django_mongodb/aggregates.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from copy import deepcopy
2-
31
from django.db.models.aggregates import Aggregate, Count, StdDev, Variance
42
from django.db.models.expressions import Case, Value, When
53
from django.db.models.lookups import IsNull
6-
from django.db.models.sql.where import WhereNode
74

85
from .query_utils import process_lhs
96

@@ -45,12 +42,9 @@ def count(self, compiler, connection, resolve_inner_expression=False, **extra_co
4542
node = self.copy()
4643
node.filter = None
4744
source_expressions = node.get_source_expressions()
48-
filter_ = deepcopy(self.filter)
49-
filter_.add(
50-
WhereNode([IsNull(source_expressions[0], True)], negated=True),
51-
filter_.default,
45+
condition = When(
46+
self.filter, then=Case(When(IsNull(source_expressions[0], False), then=Value(1)))
5247
)
53-
condition = When(filter_, then=Value(1))
5448
node.set_source_expressions([Case(condition)] + source_expressions[1:])
5549
inner_expression = process_lhs(node, compiler, connection)
5650
else:

django_mongodb/features.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
8888
"queries.tests.ValuesSubqueryTests.test_values_in_subquery",
8989
# Wrong results for distinct() queries.
9090
"admin_filters.tests.ListFiltersTests.test_emptylistfieldfilter_genericrelation",
91-
"admin_filters.tests.ListFiltersTests.test_facets_filter",
9291
}
9392
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
9493
_django_test_expected_failures_bitwise = {

0 commit comments

Comments
 (0)