Opened 2 days ago
#36062 new Bug
Deserializing CompositePrimaryKey from a string raises ValueError
Reported by: | Jacob Walls | Owned by: | |
---|---|---|---|
Component: | Core (Serialization) | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Adjusting this test (for a roundtrip from a serialized string and back) to use CompositePrimaryKey
produces a failure:
-
tests/serializers/models/base.py
diff --git a/tests/serializers/models/base.py b/tests/serializers/models/base.py index e4fcee366d..63c3590113 100644
a b class Actor(models.Model): 99 99 100 100 101 101 class Movie(models.Model): 102 pk = models.CompositePrimaryKey("actor", "title", "price") 102 103 actor = models.ForeignKey(Actor, models.CASCADE) 103 104 title = models.CharField(max_length=50) 104 105 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.
Note:
See TracTickets
for help on using tickets.