Skip to content

Commit e232791

Browse files
committed
add NotSupportedError for delete queries that use multiple collections
1 parent ad7e134 commit e232791

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

django_mongodb/compiler.py

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

267267

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

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

275282
class SQLUpdateCompiler(SQLCompiler):
276283
def execute_sql(self, result_type):

0 commit comments

Comments
 (0)