#34171: QuerySet.bulk_create() crashes on mixed case columns in
unique_fields/update_fields.
-------------------------------------+-------------------------------------
     Reporter:  joshbrooks           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * 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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184990db190-b8c598c7-c0d1-40d7-ac0a-75c1bed81c41-000000%40eu-central-1.amazonses.com.

Reply via email to