Skip to content

Commit 2f86210

Browse files
committed
fix QuerySet.annotate() with expression that raises FullResultSet
1 parent 1dbf05b commit 2f86210

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

django_mongodb/features.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
206206
"annotations.tests.NonAggregateAnnotationTestCase.test_custom_functions_can_ref_other_functions",
207207
# Floor not implemented.
208208
"annotations.tests.NonAggregateAnnotationTestCase.test_custom_transform_annotation",
209-
# annotate() with expression that raises FullResultSet crashes.
210-
"annotations.tests.NonAggregateAnnotationTestCase.test_full_expression_wrapped_annotation",
211209
# BaseDatabaseOperations may require a format_for_duration_arithmetic().
212210
"annotations.tests.NonAggregateAnnotationTestCase.test_mixed_type_annotation_date_interval",
213211
# FieldDoesNotExist with ordering.

django_mongodb/query_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import re
22

3+
from django.core.exceptions import FullResultSet
4+
from django.db.models.expressions import Value
5+
36

47
def is_direct_value(node):
58
return not hasattr(node, "as_sql")
@@ -8,7 +11,13 @@ def is_direct_value(node):
811
def process_lhs(node, compiler, connection, bare_column_ref=False):
912
if not hasattr(node, "lhs"):
1013
# node is a Func or Expression, possibly with multiple source expressions.
11-
return [expr.as_mql(compiler, connection) for expr in node.get_source_expressions()]
14+
result = []
15+
for expr in node.get_source_expressions():
16+
try:
17+
result.append(expr.as_mql(compiler, connection))
18+
except FullResultSet:
19+
result.append(Value(True).as_mql(compiler, connection))
20+
return result
1221
# node is a Transform with just one source expression, aliased as "lhs".
1322
if is_direct_value(node.lhs):
1423
return node

0 commit comments

Comments
 (0)