Skip to content

Commit b03ec92

Browse files
committed
fix "'Ref' object has no attribute 'as_mql'" query crash
1 parent 18c9da9 commit b03ec92

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,
@@ -68,6 +69,10 @@ def query(self, compiler, connection): # noqa: ARG001
6869
raise NotSupportedError("Using a QuerySet in annotate() is not supported on MongoDB.")
6970

7071

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

@@ -99,6 +104,7 @@ def register_expressions():
99104
ExpressionWrapper.as_mql = expression_wrapper
100105
NegatedExpression.as_mql = negated_expression
101106
Query.as_mql = query
107+
Ref.as_mql = ref
102108
Subquery.as_mql = subquery
103109
When.as_mql = when
104110
Value.as_mql = value

django_mongodb/features.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
102102
# pymongo.errors.OperationFailure: $multiply only supports numeric
103103
# types, not date. (should be wrapped in DatabaseError).
104104
"expressions.tests.FTimeDeltaTests.test_invalid_operator",
105-
# 'Ref' object has no attribute 'as_mql'.
106-
"expressions.tests.BasicExpressionsTests.test_aggregate_subquery_annotation",
107105
}
108106
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
109107
_django_test_expected_failures_bitwise = {
@@ -286,6 +284,7 @@ def django_test_expected_failures(self):
286284
"defer_regress.tests.DeferRegressionTest.test_basic",
287285
"defer_regress.tests.DeferRegressionTest.test_defer_annotate_select_related",
288286
"defer_regress.tests.DeferRegressionTest.test_ticket_16409",
287+
"expressions.tests.BasicExpressionsTests.test_aggregate_subquery_annotation",
289288
"expressions.tests.FieldTransformTests.test_month_aggregation",
290289
"expressions_case.tests.CaseDocumentationExamples.test_conditional_aggregation_example",
291290
# Func not implemented.

0 commit comments

Comments
 (0)