Leaklens

django__django-16315

QuerySet.bulk_create() crashes on mixed case columns in unique_fields/update_fields.

Verdict: the fix is stated in the issue (Tier A).

We should use columns instead of field names, e.g. django/db/models/query.py diff --git a/django/db/models/query.py b/django/db/models/query.py index de49e1c58c..fcf0a0616c 100644 a b class QuerySet(AltersData): 798798 self._prepare_for_bulk_create(objs) 799799 with transaction.atomic(using=self.db, savepoint=False): 800800 objs_with_pk, objs_without_pk = partition(lambda o: o.pk is None, objs) 801 if update_fields: 802 update_fields = [self.model._meta.get_field(name) for name in update_fields] 803 if unique_fields: 804 unique_fields = [self.model._meta.get_field(name) for name in unique_fields] 801805 if objs_with_pk: 802806 returned_columns = self._batched_insert( 803807 objs_with_pk, django/db/models/sql/compiler.py diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 0562a71dd1..caf36382b5 100644 a b class SQLInsertCompiler(SQLCompiler): 17251725 on_conflict_suffix_sql = self.connection.ops.on_conflict_suffix_sql( 17261726 fields, 17271727 self.query.on_conflict, 1728 self.query.update_fields, 1729 self.query.unique_fields, 1728 (f.column for f in self.query.update_fields), 1729 (f.column for f in self.query.unique_fields), 17301730 )

The text states the fix: “We should use columns instead of field names, e.g. django/db/models/query.py diff --git a/django/db/models/query.py b/django/db/models/query.py index de49e1c58c..fcf0a06…”

All SWE-bench Verified tasks · more django/django tasks · How the check works