Opened 3 months ago
Closed 3 months ago
#36569 closed Bug (duplicate)
Asymmetric quoting/unquoting of object_ids in ModelAdmin urls breaks with CharField primary keys
| Reported by: | LeGast00n | Owned by: | |
|---|---|---|---|
| Component: | contrib.admin | Version: | 5.2 |
| Severity: | Normal | Keywords: | url generation resolution escaping |
| Cc: | LeGast00n | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Problem
The Django admin consistently applies quote() when generating URLs for object_id,
but the inverse unquoting is not applied everywhere during or after URL resolution.
For models with a CharField primary key containing characters such as _,
the ChangeList → Change view object links may break, since the value is escaped in the URL
but not properly decoded on request handling.
Steps to reproduce
- Define a model with a
CharFieldas the primary key, allowing_in its values. - Register it in the Django admin.
- Go to the changelist and click the link to a change view.
Observed
- The URL is generated with
quote()escaping. - Resolution fails for pks bearing quoted characters, e.g. in changelist links, delete view, or custom admin URLs.
Workarounds
- Overriding
change_view/delete_viewto apply unquoting before callingsuper()works in some cases. - For custom admin URLs the problem happens earlier, during URL resolution itself, leaving no straightforward workaround.
Expected
Wherever quote() is used to build admin URLs, the corresponding unquoting
should also be applied consistently during URL resolution, including for custom admin routes.
Change History (2)
comment:1 by , 3 months ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 months ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
I wasn't able to replicate using the instructions above, however this is likely a duplicate of #30386 or #22226