1
0
mirror of https://github.com/django/django.git synced 2025-10-29 00:26:07 +00:00

Fixed #33322 -- Fixed loss of assigned related object when saving relation with bulk_update().

This commit is contained in:
Hannes Ljungberg
2021-11-27 16:04:39 +01:00
committed by Mariusz Felisiak
parent 9ac92b1efc
commit ed2018037d
3 changed files with 36 additions and 2 deletions

View File

@@ -549,6 +549,8 @@ class QuerySet:
raise ValueError('bulk_update() cannot be used with primary key fields.')
if not objs:
return 0
for obj in objs:
obj._prepare_related_fields_for_save(operation_name='bulk_update', fields=fields)
# PK is used twice in the resulting update query, once in the filter
# and once in the WHEN. Each field will also have one CAST.
connection = connections[self.db]