Skip to content

Commit 9f58a00

Browse files
committed
Fix bulk_update unit tests
1 parent 2b7f9b5 commit 9f58a00

File tree

2 files changed

+191
-191
lines changed

2 files changed

+191
-191
lines changed

mssql/functions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def bulk_update_with_default(self, objs, fields, batch_size=None, default=0):
238238
if any(f.primary_key for f in fields):
239239
raise ValueError('bulk_update() cannot be used with primary key fields.')
240240
if not objs:
241-
return
241+
return 0
242242
# PK is used twice in the resulting update query, once in the filter
243243
# and once in the WHEN. Each field will also have one CAST.
244244
max_batch_size = connections[self.db].ops.bulk_batch_size(['pk', 'pk'] + fields, objs)
@@ -266,9 +266,11 @@ def bulk_update_with_default(self, objs, fields, batch_size=None, default=0):
266266
case_statement = Cast(case_statement, output_field=field)
267267
update_kwargs[field.attname] = case_statement
268268
updates.append(([obj.pk for obj in batch_objs], update_kwargs))
269+
rows_updated = 0
269270
with transaction.atomic(using=self.db, savepoint=False):
270271
for pks, update_kwargs in updates:
271-
self.filter(pk__in=pks).update(**update_kwargs)
272+
rows_updated += self.filter(pk__in=pks).update(**update_kwargs)
273+
return rows_updated
272274

273275
ATan2.as_microsoft = sqlserver_atan2
274276
In.split_parameter_list_as_sql = split_parameter_list_as_sql

0 commit comments

Comments
 (0)