#36068: bulk_create() update_fields argument accepts fields participating in a
composite primary key
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                     Type:
                                     |  Cleanup/optimization
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  dev                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 `bulk_create()`
 
[https://github.com/django/django/blob/40d5516385448a73426aad396778f369a363eda9/tests/bulk_create/tests.py#L540
 rejects] primary key fields provided to the `update_fields` argument. I
 think I would expect any fields participating in a composite primary key
 to also be subject to that constraint.

 Failing test:

 {{{#!diff
 diff --git a/tests/composite_pk/test_create.py
 b/tests/composite_pk/test_create.py
 index 7c9925b946..77a84fc53d 100644
 --- a/tests/composite_pk/test_create.py
 +++ b/tests/composite_pk/test_create.py
 @@ -77,6 +77,19 @@ class CompositePKCreateTests(TestCase):
          self.assertEqual(obj_3.pk, (obj_3.tenant_id, obj_3.id))
          self.assertEqual(obj_3.email, "[email protected]")

 +    def test_bulk_create_user_with_disallowed_update_fields(self):
 +        objs = [User(tenant=self.tenant, id=8291,
 email="[email protected]")] * 2
 +        msg = "bulk_create() cannot be used with primary keys in update
 fields"
 +        with self.assertRaisesMessage(ValueError, msg):
 +            User.objects.bulk_create(
 +                objs,
 +                update_conflicts=True,
 +                update_fields=["tenant_id"],
 +                unique_fields=["id", "tenant_id"],
 +            )
 +        # instead produces:
 +        # [<User: User object ((1, 8291))>, <User: User object ((1,
 8291))>]
 +
      def test_get_or_create_user(self):
          test_cases = (
              {
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36068>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701943ef813be-41e10bed-7ff0-429e-bb4c-425b343aed5b-000000%40eu-central-1.amazonses.com.

Reply via email to