Skip to content

Commit c4645c9

Browse files
authored
add support for expression default value when it raises EmptyResultSet
1 parent 72ca2ab commit c4645c9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

django_mongodb/compiler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,11 @@ def get_project_fields(self, columns=None, ordering=None, force_expression=False
550550
else expr.as_mql(self, self.connection)
551551
)
552552
except EmptyResultSet:
553-
fields[collection][name] = Value(False).as_mql(self, self.connection)
553+
empty_result_set_value = getattr(expr, "empty_result_set_value", NotImplemented)
554+
value = (
555+
False if empty_result_set_value is NotImplemented else empty_result_set_value
556+
)
557+
fields[collection][name] = Value(value).as_mql(self, self.connection)
554558
except FullResultSet:
555559
fields[collection][name] = Value(True).as_mql(self, self.connection)
556560
# Annotations (stored in None) and the main collection's fields

django_mongodb/features.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
7373
"backends.tests.ThreadTests.test_pass_connection_between_threads",
7474
"backends.tests.ThreadTests.test_closing_non_shared_connections",
7575
"backends.tests.ThreadTests.test_default_connection_thread_local",
76-
# Column default values aren't handled when a field raises
77-
# EmptyResultSet: https://github.com/mongodb-labs/django-mongodb/issues/155
78-
"annotations.tests.NonAggregateAnnotationTestCase.test_empty_queryset_annotation",
79-
"db_functions.comparison.test_coalesce.CoalesceTests.test_empty_queryset",
8076
# Union as subquery is not mapping the parent parameter and collections:
8177
# https://github.com/mongodb-labs/django-mongodb/issues/156
8278
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_in_subquery_related_outerref",

0 commit comments

Comments
 (0)