From 9d780fc41056733f16622f072afeef0212ec1cb8 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 17 Dec 2024 19:38:02 -0500 Subject: [PATCH] fix per Emanuel --- django_mongodb/aggregates.py | 4 ++-- django_mongodb/compiler.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django_mongodb/aggregates.py b/django_mongodb/aggregates.py index 6d7b2069..e67cefa2 100644 --- a/django_mongodb/aggregates.py +++ b/django_mongodb/aggregates.py @@ -1,5 +1,5 @@ from django.db.models.aggregates import Aggregate, Count, StdDev, Variance -from django.db.models.expressions import Case, Col, Value, When +from django.db.models.expressions import Case, Value, When from django.db.models.lookups import IsNull from .query_utils import process_lhs @@ -16,7 +16,7 @@ def aggregate( resolve_inner_expression=False, **extra_context, # noqa: ARG001 ): - if self.filter and not isinstance(self.filter, Col): + if self.filter: node = self.copy() node.filter = None source_expressions = node.get_source_expressions() diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index 46d3afaa..a0508cf5 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -91,7 +91,7 @@ def _prepare_expressions_for_pipeline(self, expression, target, annotation_group rhs = sub_expr.as_mql(self, self.connection, resolve_inner_expression=True) group[alias] = {"$addToSet": rhs} replacing_expr = sub_expr.copy() - replacing_expr.set_source_expressions([inner_column]) + replacing_expr.set_source_expressions([inner_column, None]) else: group[alias] = sub_expr.as_mql(self, self.connection) replacing_expr = inner_column