[Django] #36062: Deserializing CompositePrimaryKey from a string raises ValueError

25 views
Skip to first unread message

Django

unread,
Jan 3, 2025, 9:28:05 PM1/3/25
to django-...@googlegroups.com
#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.

Django

unread,
Jan 6, 2025, 3:16:34 AM1/6/25
to django-...@googlegroups.com
#36062: Deserializing CompositePrimaryKey from a string raises ValueError
--------------------------------------+------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Core (Serialization) | Version: dev
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 Sarah Boyce):

* cc: Csirmaz Bendegúz (added)
* stage: Unreviewed => Accepted

Comment:

Thank you!
--
Ticket URL: <https://code.djangoproject.com/ticket/36062#comment:1>
Reply all
Reply to author
Forward
0 new messages