Skip to content

Commit 450dbb3

Browse files
WaVEVtimgraham
authored andcommitted
use IsNull for Count() filtering
This fixes the case where the source expression is a foreign field.
1 parent 7dd6e0d commit 450dbb3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

django_mongodb/aggregates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from django.db.models.aggregates import Aggregate, Count, StdDev, Variance
44
from django.db.models.expressions import Case, Value, When
5-
from django.db.models.lookups import Exact
5+
from django.db.models.lookups import IsNull
66
from django.db.models.sql.where import WhereNode
77

88
from .query_utils import process_lhs
@@ -47,7 +47,7 @@ def count(self, compiler, connection, resolve_inner_expression=False, **extra_co
4747
source_expressions = node.get_source_expressions()
4848
filter_ = deepcopy(self.filter)
4949
filter_.add(
50-
WhereNode([Exact(source_expressions[0], Value(None))], negated=True),
50+
WhereNode([IsNull(source_expressions[0], True)], negated=True),
5151
filter_.default,
5252
)
5353
condition = When(filter_, then=Value(1))

0 commit comments

Comments
 (0)