From fc31ef885dc776d2a169cde943f37356eceb4cf9 Mon Sep 17 00:00:00 2001 From: Tom Forbes Date: Sun, 24 Nov 2024 18:27:40 +0000 Subject: [PATCH] Update django/db/models/sql/compiler.py Co-authored-by: Lily Foote --- django/db/models/sql/compiler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 64a9fb7457..fcbcb98bf1 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -2093,12 +2093,12 @@ class SQLUpdateCompiler(SQLCompiler): class SQLBulkUpdateCompiler(SQLCompiler): def execute_sql(self, result_type): cursor = super().execute_sql(result_type) + if not cursor: + return 0 try: - rows = cursor.rowcount if cursor else 0 + return cursor.rowcount finally: - if cursor: - cursor.close() - return rows + cursor.close() def get_update_clause(self, values): qn = self.quote_name_unless_alias