Skip to content

Commit 5b46160

Browse files
committed
make QuerySet.extra(select=... and where=...) raise NotSupportedError
- PR review fixes
1 parent b84aae2 commit 5b46160

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

django_mongodb/expressions.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
When,
2323
)
2424
from django.db.models.sql import Query
25-
from django.db.models.sql.where import ExtraWhere
2625

2726

2827
def case(self, compiler, connection):
@@ -68,10 +67,6 @@ def expression_wrapper(self, compiler, connection):
6867
return self.expression.as_mql(compiler, connection)
6968

7069

71-
def extra_where(self, compiler, connection): # noqa: ARG001
72-
raise NotSupportedError("QuerySet extras are not supported on MongoDB.")
73-
74-
7570
def f(self, compiler, connection): # noqa: ARG001
7671
return f"${self.name}"
7772

@@ -87,8 +82,10 @@ def order_by(self, compiler, connection):
8782
def query(self, compiler, connection): # noqa: ARG001
8883
raise NotSupportedError("Using a QuerySet in annotate() is not supported on MongoDB.")
8984

85+
9086
def raw_sql(self, compiler, connection): # noqa: ARG001
91-
raise NotSupportedError("QuerySet extras are not supported on MongoDB.")
87+
raise NotSupportedError("RawSQL is not supported on MongoDB.")
88+
9289

9390
def ref(self, compiler, connection): # noqa: ARG001
9491
prefix = (
@@ -133,7 +130,6 @@ def register_expressions():
133130
Case.as_mql = case
134131
Col.as_mql = col
135132
CombinedExpression.as_mql = combined_expression
136-
ExtraWhere.as_mql = extra_where
137133
ExpressionWrapper.as_mql = expression_wrapper
138134
F.as_mql = f
139135
NegatedExpression.as_mql = negated_expression

django_mongodb/features.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ def django_test_expected_failures(self):
493493
"queries.tests.ValuesQuerysetTests.test_named_values_list_with_fields",
494494
"queries.tests.ValuesQuerysetTests.test_named_values_list_without_fields",
495495
"select_related.tests.SelectRelatedTests.test_select_related_with_extra",
496+
"aggregation_regress.tests.AggregationTests.test_annotate_with_extra",
497+
"aggregation_regress.tests.AggregationTests.test_annotation",
498+
"aggregation_regress.tests.AggregationTests.test_more_more3",
499+
"aggregation_regress.tests.AggregationTests.test_more_more_more3",
500+
"many_to_one.tests.ManyToOneTests.test_selects",
496501
},
497502
"Test inspects query for SQL": {
498503
"aggregation.tests.AggregateAnnotationPruningTests.test_non_aggregate_annotation_pruned",
@@ -664,17 +669,6 @@ def django_test_expected_failures(self):
664669
"backends.base.test_base.DatabaseWrapperLoggingTests",
665670
"migrations.test_operations.OperationTests.test_run_python_atomic",
666671
},
667-
"QuerySet extras are not supported on MongoDB": {
668-
# QuerySet.extra(select=...) raises NotSupportedError instead of:
669-
# 'RawSQL' object has no attribute 'as_mql'.
670-
"aggregation_regress.tests.AggregationTests.test_annotate_with_extra",
671-
"aggregation_regress.tests.AggregationTests.test_annotation",
672-
"aggregation_regress.tests.AggregationTests.test_more_more3",
673-
"aggregation_regress.tests.AggregationTests.test_more_more_more3",
674-
# QuerySet.extra(where=...) should raise NotSupportedError instead of:
675-
# 'ExtraWhere' object has no attribute 'as_mql'.
676-
"many_to_one.tests.ManyToOneTests.test_selects",
677-
},
678672
}
679673

680674
@cached_property

django_mongodb/query.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from operator import add as add_operator
33

44
from django.core.exceptions import EmptyResultSet, FullResultSet
5-
from django.db import DatabaseError, IntegrityError
5+
from django.db import DatabaseError, IntegrityError, NotSupportedError
66
from django.db.models.expressions import Case, When
77
from django.db.models.functions import Mod
88
from django.db.models.lookups import Exact
99
from django.db.models.sql.constants import INNER
1010
from django.db.models.sql.datastructures import Join
11-
from django.db.models.sql.where import AND, OR, XOR, NothingNode, WhereNode
11+
from django.db.models.sql.where import AND, OR, XOR, ExtraWhere, NothingNode, WhereNode
1212
from pymongo.errors import DuplicateKeyError, PyMongoError
1313

1414

@@ -231,7 +231,12 @@ def where_node(self, compiler, connection):
231231
return mql
232232

233233

234+
def extra_where(self, compiler, connection): # noqa: ARG001
235+
raise NotSupportedError("QuerySet.extra() is not supported on MongoDB.")
236+
237+
234238
def register_nodes():
235239
Join.as_mql = join
236240
NothingNode.as_mql = NothingNode.as_sql
237241
WhereNode.as_mql = where_node
242+
ExtraWhere.as_mql = extra_where

0 commit comments

Comments
 (0)