Skip to content

Commit

Permalink
fix QuerySet.delete() crash when it raises EmptyResultSet
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Dec 26, 2024
1 parent c90a00c commit a40e0ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,13 @@ def collection_name(self):
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
def execute_sql(self, result_type=MULTI):
cursor = Cursor()
cursor.rowcount = self.build_query().delete()
try:
query = self.build_query()
except EmptyResultSet:
rowcount = 0
else:
rowcount = query.delete()
cursor.rowcount = rowcount
return cursor

def check_query(self):
Expand Down

0 comments on commit a40e0ae

Please sign in to comment.