Skip to content

Commit 41598ec

Browse files
aclark4lifetimgraham
authored andcommitted
make QuerySet.extra(select=... and where=...) raise NotSupportedError
1 parent 8b98b58 commit 41598ec

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

django_mongodb/expressions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
F,
1414
NegatedExpression,
1515
OrderBy,
16+
RawSQL,
1617
Ref,
1718
ResolvedOuterRef,
1819
Star,
@@ -82,6 +83,10 @@ def query(self, compiler, connection): # noqa: ARG001
8283
raise NotSupportedError("Using a QuerySet in annotate() is not supported on MongoDB.")
8384

8485

86+
def raw_sql(self, compiler, connection): # noqa: ARG001
87+
raise NotSupportedError("RawSQL is not supported on MongoDB.")
88+
89+
8590
def ref(self, compiler, connection): # noqa: ARG001
8691
prefix = (
8792
f"{self.source.alias}."
@@ -130,6 +135,7 @@ def register_expressions():
130135
NegatedExpression.as_mql = negated_expression
131136
OrderBy.as_mql = order_by
132137
Query.as_mql = query
138+
RawSQL.as_mql = raw_sql
133139
Ref.as_mql = ref
134140
ResolvedOuterRef.as_mql = ResolvedOuterRef.as_sql
135141
Star.as_mql = star

django_mongodb/features.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
6868
"aggregation.tests.AggregateTestCase.test_reverse_fkey_annotate",
6969
"aggregation_regress.tests.AggregationTests.test_annotation_disjunction",
7070
"aggregation_regress.tests.AggregationTests.test_decimal_aggregate_annotation_filter",
71-
# QuerySet.extra(select=...) should raise NotSupportedError instead of:
72-
# 'RawSQL' object has no attribute 'as_mql'.
73-
"aggregation_regress.tests.AggregationTests.test_annotate_with_extra",
74-
"aggregation_regress.tests.AggregationTests.test_annotation",
75-
"aggregation_regress.tests.AggregationTests.test_more_more3",
76-
"aggregation_regress.tests.AggregationTests.test_more_more_more3",
77-
# QuerySet.extra(where=...) should raise NotSupportedError instead of:
78-
# 'ExtraWhere' object has no attribute 'as_mql'.
79-
"many_to_one.tests.ManyToOneTests.test_selects",
8071
# Incorrect JOIN with GenericRelation gives incorrect results.
8172
"aggregation_regress.tests.AggregationTests.test_aggregation_with_generic_reverse_relation",
8273
"generic_relations.tests.GenericRelationsTests.test_queries_content_type_restriction",
@@ -484,6 +475,7 @@ def django_test_expected_failures(self):
484475
"delete_regress.tests.Ticket19102Tests.test_ticket_19102_extra",
485476
"lookup.tests.LookupTests.test_values",
486477
"lookup.tests.LookupTests.test_values_list",
478+
"many_to_one.tests.ManyToOneTests.test_selects",
487479
"ordering.tests.OrderingTests.test_extra_ordering",
488480
"ordering.tests.OrderingTests.test_extra_ordering_quoting",
489481
"ordering.tests.OrderingTests.test_extra_ordering_with_table_name",
@@ -519,6 +511,10 @@ def django_test_expected_failures(self):
519511
},
520512
"Test executes raw SQL.": {
521513
"aggregation.tests.AggregateTestCase.test_coalesced_empty_result_set",
514+
"aggregation_regress.tests.AggregationTests.test_annotate_with_extra",
515+
"aggregation_regress.tests.AggregationTests.test_annotation",
516+
"aggregation_regress.tests.AggregationTests.test_more_more3",
517+
"aggregation_regress.tests.AggregationTests.test_more_more_more3",
522518
"annotations.tests.NonAggregateAnnotationTestCase.test_raw_sql_with_inherited_field",
523519
"backends.base.test_base.ExecuteWrapperTests",
524520
"backends.tests.BackendTestCase.test_cursor_contextmanager",

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

@@ -92,6 +92,10 @@ def get_pipeline(self):
9292
return pipeline
9393

9494

95+
def extra_where(self, compiler, connection): # noqa: ARG001
96+
raise NotSupportedError("QuerySet.extra() is not supported on MongoDB.")
97+
98+
9599
def join(self, compiler, connection):
96100
lookup_pipeline = []
97101
lhs_fields = []
@@ -232,6 +236,7 @@ def where_node(self, compiler, connection):
232236

233237

234238
def register_nodes():
239+
ExtraWhere.as_mql = extra_where
235240
Join.as_mql = join
236241
NothingNode.as_mql = NothingNode.as_sql
237242
WhereNode.as_mql = where_node

0 commit comments

Comments
 (0)