[Django] #36482: Admin renders complex PKs incorrectly

16 views
Skip to first unread message

Django

unread,
Jun 27, 2025, 9:58:29 AM6/27/25
to django-...@googlegroups.com
#36482: Admin renders complex PKs incorrectly
-------------------------------+-----------------------------------------
Reporter: David Sanders | Type: Bug
Status: new | Component: contrib.admin
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
-------------------------------+-----------------------------------------
Admin creates links to edit/history/etc pages by rendering the PK directly
as a string - either explicitly in Python or implicitly in one of the
templates.

However when the instance is retrieved in `get_object()` it uses
`field.to_python(value)` like so:
https://github.com/django/django/blob/a3882876927a819ca982ea61353945e9d86f3659/django/contrib/admin/options.py#L886

This creates an asymmetrical serialisation-deserialisation process which,
while is fine for integers, will fail for things more complex.

The correct serialisation of pk would be the inverse of `to_python()`:
`field.value_to_string(obj)`.

Note this is related to #35953: The fix for this would also be useful to
get composite PKs working - at least for rendering the PK.

I noticed this while trying out `DateTimeRangeField()` as part of the PK
for temporal models as the `valid_time` – this field type uses specific
json serialisation which is quite verbose in the URL but works (have
tested it will post proposed patch in a draft PR)
--
Ticket URL: <https://code.djangoproject.com/ticket/36482>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 27, 2025, 10:07:25 AM6/27/25
to django-...@googlegroups.com
#36482: Admin renders complex PKs incorrectly
-------------------------------+--------------------------------------
Reporter: David Sanders | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by David Sanders):

Draft PR: https://github.com/django/django/pull/19600
--
Ticket URL: <https://code.djangoproject.com/ticket/36482#comment:1>

Django

unread,
Jun 27, 2025, 1:20:30 PM6/27/25
to django-...@googlegroups.com
#36482: Admin renders complex PKs incorrectly
-------------------------------+------------------------------------
Reporter: David Sanders | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | 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 Simon Charette):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36482#comment:2>

Django

unread,
Jun 28, 2025, 3:46:56 AM6/28/25
to django-...@googlegroups.com
#36482: Admin renders complex PKs incorrectly
-------------------------------+-----------------------------------------
Reporter: David Sanders | Owner: David Sanders
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by David Sanders):

* has_patch: 0 => 1
* owner: (none) => David Sanders
* status: new => assigned

Comment:

I think I've got something worth reviewing now 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/36482#comment:3>

Django

unread,
Jul 17, 2025, 8:27:32 AM7/17/25
to django-...@googlegroups.com
#36482: Admin renders complex PKs incorrectly
-------------------------------+-----------------------------------------
Reporter: David Sanders | Owner: David Sanders
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by Sarah Boyce):

* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36482#comment:4>
Reply all
Reply to author
Forward
0 new messages