Skip to content

Commit 6b18784

Browse files
committed
add NotSupportedError for delete queries that use multiple collections
1 parent 4404656 commit 6b18784

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Migrations for 'admin':
112112
- `aggregate()`
113113
- `dates()`
114114
- `datetimes()`
115+
- `delete()`, if the query uses multiple collections.
115116
- `distinct()`
116117
- `extra()`
117118
- `prefetch_related()`

django_mongodb/compiler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,19 @@ def insert(self, docs, returning_fields=None):
267267
return inserted_ids if returning_fields else []
268268

269269

270-
class SQLDeleteCompiler(SQLCompiler):
270+
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
271271
def execute_sql(self, result_type=MULTI):
272272
cursor = Cursor()
273273
cursor.rowcount = self.build_query([self.query.get_meta().pk]).delete()
274274
return cursor
275275

276+
def check_query(self):
277+
super().check_query()
278+
if not self.single_alias:
279+
raise NotSupportedError(
280+
"Cannot use QuerySet.delete() when querying across multiple collections on MongoDB."
281+
)
282+
276283

277284
class SQLUpdateCompiler(SQLCompiler):
278285
def execute_sql(self, result_type):

0 commit comments

Comments
 (0)