* severity: Normal => Release blocker
* cc: Chih Sean Hsu (added)
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Thanks for the report! Bug in 0f6946495a8ec955b471ca1baaf408ceb53d4796. We
should use columns instead of field names, e.g.
{{{#!diff
diff --git a/django/db/models/query.py b/django/db/models/query.py
index de49e1c58c..fcf0a0616c 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -798,6 +798,10 @@ class QuerySet(AltersData):
self._prepare_for_bulk_create(objs)
with transaction.atomic(using=self.db, savepoint=False):
objs_with_pk, objs_without_pk = partition(lambda o: o.pk is
None, objs)
+ if update_fields:
+ update_fields = [self.model._meta.get_field(name) for
name in update_fields]
+ if unique_fields:
+ unique_fields = [self.model._meta.get_field(name) for
name in unique_fields]
if objs_with_pk:
returned_columns = self._batched_insert(
objs_with_pk,
diff --git a/django/db/models/sql/compiler.py
b/django/db/models/sql/compiler.py
index 0562a71dd1..caf36382b5 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1725,8 +1725,8 @@ class SQLInsertCompiler(SQLCompiler):
on_conflict_suffix_sql =
self.connection.ops.on_conflict_suffix_sql(
fields,
self.query.on_conflict,
- self.query.update_fields,
- self.query.unique_fields,
+ (f.column for f in self.query.update_fields),
+ (f.column for f in self.query.unique_fields),
)
if (
self.returning_fields
}}}
Would you like to prepare a patch? (regression tests are required)
--
Ticket URL: <https://code.djangoproject.com/ticket/34171#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.