mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #27026 -- Fixed state initialization of bulk_create() objects if can_return_ids_from_bulk_insert.
This commit is contained in:
parent
fc8f097117
commit
3246d2b4bb
3 changed files with 19 additions and 2 deletions
|
@ -452,8 +452,10 @@ class QuerySet(object):
|
|||
ids = self._batched_insert(objs_without_pk, fields, batch_size)
|
||||
if connection.features.can_return_ids_from_bulk_insert:
|
||||
assert len(ids) == len(objs_without_pk)
|
||||
for i in range(len(ids)):
|
||||
objs_without_pk[i].pk = ids[i]
|
||||
for obj_without_pk, pk in zip(objs_without_pk, ids):
|
||||
obj_without_pk.pk = pk
|
||||
obj_without_pk._state.adding = False
|
||||
obj_without_pk._state.db = self.db
|
||||
|
||||
return objs
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue