* cc: Chih Sean Hsu (added)
* stage: Unreviewed => Accepted
Comment:
Thanks for the ticket. I've checked and it works on PostgreSQL, MariaDB
10.5+, and SQLite 3.35+:
{{{#!diff
diff --git a/django/db/models/query.py b/django/db/models/query.py
index a5b0f464a9..f1e052cb36 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1837,12 +1837,15 @@ class QuerySet(AltersData):
inserted_rows = []
bulk_return =
connection.features.can_return_rows_from_bulk_insert
for item in [objs[i : i + batch_size] for i in range(0,
len(objs), batch_size)]:
- if bulk_return and on_conflict is None:
+ if bulk_return and (on_conflict is None or on_conflict ==
OnConflict.UPDATE):
inserted_rows.extend(
self._insert(
item,
fields=fields,
using=self.db,
+ on_conflict=on_conflict,
+ update_fields=update_fields,
+ unique_fields=unique_fields,
returning_fields=self.model._meta.db_returning_fields,
)
)
}}}
Would you like to prepare a patch via GitHub PR? (docs changes and tests
are required)
--
Ticket URL: <https://code.djangoproject.com/ticket/34698#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.