Skip to content

Commit c9796ab

Browse files
committed
Refactor.
1 parent d97a3d4 commit c9796ab

File tree

5 files changed

+8
-17
lines changed

5 files changed

+8
-17
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ from the new application's `apps.py` file.
114114
- `QuerySet.delete()` and `update()` do not support queries that span multiple
115115
collections.
116116

117-
- `QuerySet` in `QuerySet.annotate()` aren't supported.
118-
119117
- `DateTimeField` doesn't support microsecond precision, and correspondingly,
120118
`DurationField` stores milliseconds rather than microseconds.
121119

django_mongodb/compiler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,7 @@ def execute_sql(self, result_type=MULTI):
685685
def check_query(self):
686686
super().check_query()
687687
if not self.single_alias:
688-
raise NotSupportedError(
689-
"Cannot use QuerySet.delete() when querying across multiple collections on MongoDB."
690-
)
688+
raise NotSupportedError("Cannot use QuerySet.delete() when a subquery is required.")
691689

692690
def get_where(self):
693691
return self.query.where

django_mongodb/features.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,23 +326,18 @@ def django_test_expected_failures(self):
326326
"aggregation.tests.AggregateAnnotationPruningTests.test_unused_aliased_aggregate_pruned",
327327
"aggregation.tests.AggregateAnnotationPruningTests.test_referenced_aggregate_annotation_kept",
328328
"aggregation.tests.AggregateTestCase.test_count_star",
329-
"aggregation.tests.AggregateAnnotationPruningTests.test_referenced_composed_subquery_requires_wrapping",
330-
"aggregation.tests.AggregateAnnotationPruningTests.test_referenced_subquery_requires_wrapping",
331-
"aggregation.tests.AggregateTestCase.test_aggregation_subquery_annotation",
332-
"aggregation.tests.AggregateTestCase.test_aggregation_subquery_annotation_related_field",
333329
"delete.tests.DeletionTests.test_only_referenced_fields_selected",
334330
"expressions.tests.ExistsTests.test_optimizations",
335331
"lookup.tests.LookupTests.test_in_ignore_none",
336332
"lookup.tests.LookupTests.test_textfield_exact_null",
337333
"migrations.test_commands.MigrateTests.test_migrate_syncdb_app_label",
338334
"migrations.test_commands.MigrateTests.test_migrate_syncdb_deferred_sql_executed_with_schemaeditor",
339-
"queries.tests.ExcludeTests.test_exclude_multivalued_exists",
340335
"queries.tests.ExistsSql.test_exists",
341336
"queries.tests.Queries6Tests.test_col_alias_quoted",
342337
"schema.tests.SchemaTests.test_rename_column_renames_deferred_sql_references",
343338
"schema.tests.SchemaTests.test_rename_table_renames_deferred_sql_references",
344339
},
345-
"Subqueries cannot be used in delete operations": {
340+
"Cannot use QuerySet.delete() when a subquery is required.": {
346341
"delete_regress.tests.DeleteTests.test_self_reference_with_through_m2m_at_second_level",
347342
"many_to_many.tests.ManyToManyTests.test_assign",
348343
"many_to_many.tests.ManyToManyTests.test_assign_ids",

django_mongodb/lookups.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def field_resolve_expression_parameter(self, compiler, connection, sql, param):
3636
def in_(self, compiler, connection):
3737
if isinstance(self.lhs, MultiColSource):
3838
raise NotImplementedError("MultiColSource is not supported.")
39+
db_rhs = getattr(self.rhs, "_db", None)
40+
if db_rhs is not None and db_rhs != connection.alias:
41+
raise ValueError(
42+
"Subqueries aren't allowed across different databases. Force "
43+
"the inner query to be evaluated using `list(inner_query)`."
44+
)
3945
return builtin_lookup(self, compiler, connection)
4046

4147

django_mongodb/query_utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ def process_lhs(node, compiler, connection):
2727

2828
def process_rhs(node, compiler, connection):
2929
rhs = node.rhs
30-
db_rhs = getattr(rhs, "_db", None)
31-
if db_rhs is not None and db_rhs != connection.alias:
32-
raise ValueError(
33-
"Subqueries aren't allowed across different databases. Force "
34-
"the inner query to be evaluated using `list(inner_query)`."
35-
)
3630
if hasattr(rhs, "as_mql"):
3731
if getattr(rhs, "subquery", False):
3832
value = rhs.as_mql(compiler, connection, lookup_name=node.lookup_name)

0 commit comments

Comments
 (0)