mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #29367 -- Fixed model state on objects with a primary key created with QuerySet.bulk_create().
This commit is contained in:
parent
3246ad1065
commit
6d1f576945
2 changed files with 12 additions and 0 deletions
|
@ -457,6 +457,9 @@ class QuerySet:
|
|||
objs_with_pk, objs_without_pk = partition(lambda o: o.pk is None, objs)
|
||||
if objs_with_pk:
|
||||
self._batched_insert(objs_with_pk, fields, batch_size)
|
||||
for obj_with_pk in objs_with_pk:
|
||||
obj_with_pk._state.adding = False
|
||||
obj_with_pk._state.db = self.db
|
||||
if objs_without_pk:
|
||||
fields = [f for f in fields if not isinstance(f, AutoField)]
|
||||
ids = self._batched_insert(objs_without_pk, fields, batch_size)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue