Skip to content

Commit ca79a96

Browse files
committed
fix "'Ref' object has no attribute 'as_mql'" query crash
1 parent fde2022 commit ca79a96

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

django_mongodb/expressions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
CombinedExpression,
1111
ExpressionWrapper,
1212
NegatedExpression,
13+
Ref,
1314
Subquery,
1415
Value,
1516
When,
@@ -66,6 +67,10 @@ def query(self, compiler, connection): # noqa: ARG001
6667
raise NotSupportedError("Using a QuerySet in annotate() is not supported on MongoDB.")
6768

6869

70+
def ref(self, compiler, connection): # noqa: ARG001
71+
return self.refs
72+
73+
6974
def subquery(self, compiler, connection): # noqa: ARG001
7075
raise NotSupportedError(f"{self.__class__.__name__} is not supported on MongoDB.")
7176

@@ -97,6 +102,7 @@ def register_expressions():
97102
ExpressionWrapper.as_mql = expression_wrapper
98103
NegatedExpression.as_mql = negated_expression
99104
Query.as_mql = query
105+
Ref.as_mql = ref
100106
Subquery.as_mql = subquery
101107
When.as_mql = when
102108
Value.as_mql = value

django_mongodb/features.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
6767
# pymongo.errors.OperationFailure: $multiply only supports numeric
6868
# types, not date. (should be wrapped in DatabaseError).
6969
"expressions.tests.FTimeDeltaTests.test_invalid_operator",
70-
# 'Ref' object has no attribute 'as_mql'.
71-
"expressions.tests.BasicExpressionsTests.test_aggregate_subquery_annotation",
7270
}
7371
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
7472
_django_test_expected_failures_bitwise = {
@@ -251,6 +249,7 @@ def django_test_expected_failures(self):
251249
"annotations.tests.NonAggregateAnnotationTestCase.test_full_expression_annotation_with_aggregation",
252250
"annotations.tests.NonAggregateAnnotationTestCase.test_grouping_by_q_expression_annotation",
253251
"annotations.tests.NonAggregateAnnotationTestCase.test_q_expression_annotation_with_aggregation",
252+
"expressions.tests.BasicExpressionsTests.test_aggregate_subquery_annotation",
254253
"expressions.tests.FieldTransformTests.test_month_aggregation",
255254
"expressions_case.tests.CaseDocumentationExamples.test_conditional_aggregation_example",
256255
# Func not implemented.

0 commit comments

Comments
 (0)