#36062: Deserializing CompositePrimaryKey from a string raises ValueError
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                     Type:  Bug
       Status:  new                  |                Component:  Core
                                     |  (Serialization)
      Version:  dev                  |                 Severity:  Release
                                     |  blocker
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 Adjusting this test (for a roundtrip from a serialized string and back) to
 use `CompositePrimaryKey` produces a failure:
 {{{#!diff
 diff --git a/tests/serializers/models/base.py
 b/tests/serializers/models/base.py
 index e4fcee366d..63c3590113 100644
 --- a/tests/serializers/models/base.py
 +++ b/tests/serializers/models/base.py
 @@ -99,6 +99,7 @@ class Actor(models.Model):


  class Movie(models.Model):
 +    pk = models.CompositePrimaryKey("actor", "title", "price")
      actor = models.ForeignKey(Actor, models.CASCADE)
      title = models.CharField(max_length=50)
      price = models.DecimalField(max_digits=6, decimal_places=2,
 default=Decimal("0.00"))
 }}}
 {{{
 ERROR: test_serialize_unicode_roundtrip
 (serializers.test_xml.XmlSerializerTestCase.test_serialize_unicode_roundtrip)
 Unicode makes the roundtrip intact
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/Users/.../django/tests/serializers/tests.py", line 241, in
 test_serialize_unicode_roundtrip
     obj_list = list(serializers.deserialize(self.serializer_name,
 serial_str))
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/.../django/django/core/serializers/xml_serializer.py", line
 214, in __next__
     return self._handle_object(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/.../django/django/core/serializers/xml_serializer.py", line
 289, in _handle_object
     obj = base.build_instance(Model, data, self.db)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/.../django/django/core/serializers/base.py", line 325, in
 build_instance
     return Model(**data)
            ^^^^^^^^^^^^^
   File "/Users/.../django/django/db/models/base.py", line 566, in __init__
     _setattr(self, prop, value)
   File "/Users/.../django/django/db/models/fields/composite.py", line 36,
 in __set__
     raise ValueError(f"{self.field.name!r} must be a list or a tuple.")
 ValueError: 'pk' must be a list or a tuple.

 ----------------------------------------------------------------------
 Ran 212 tests in 7.973s

 FAILED (errors=1)
 }}}

 Other unit tests using other test models fail if adjusted in the same way,
 so this is not isolated to the xml serializer.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36062>
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/010701942f240e06-2928ff0b-aec3-4c43-8b23-523ffb4dbf82-000000%40eu-central-1.amazonses.com.

Reply via email to