From a40e0ae1fc711acab862ab14e376da91c665cf7d Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 26 Dec 2024 18:26:09 -0500 Subject: [PATCH] fix QuerySet.delete() crash when it raises EmptyResultSet --- django_mongodb/compiler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index 46d3afaa..55749ede 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -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):