Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28460 closed Bug (duplicate)

CharField primary keys with underscores are reversed incorrectly in admin links

Reported by: cypreess Owned by: nobody
Component: contrib.admin Version: 1.11
Severity: Normal 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

This bug is probably related to ticket #22266 and it still appears in 1.11.2

1) I am using CharField for models primary key fields. Example value of id field for custom User model: usr_12345
2) In admin list view ID's are represented corectly: usr_12345
3) In admin object detail view link to the page contains extra 5F after underscore /admin/accounts/user/usr_5F12345/change/

Somehow the problem affects 3rd party apps (I am trying to use django-loginas) which renders in template link: {% url 'loginas-user-login' object_id %} ending up redirecting to incorrect link /admin/login/user/usr_5F12345/ (which will do 404 because User usr_5F12345 is not existing obviously).

However at the same time reverse function seems to work fine:

>>> reverse("loginas-user-login", args=['usr_12345'])
'/admin/login/user/usr_12345/'

which is confusing.

Change History (2)

comment:1 by Tim Graham, 7 years ago

Component: Uncategorizedcontrib.admin
Resolution: duplicate
Status: newclosed
Type: UncategorizedBug

Looks like a duplicate of #22226. When reversing, you need to use django.contrib.admin.utils.quote() or the admin_urlquote template filter on the primary key.

comment:2 by Tim Graham, 7 years ago

Summary: CharField primary keys with underscores are reversed incorectly in admin linksCharField primary keys with underscores are reversed incorrectly in admin links
Note: See TracTickets for help on using tickets.
Back to Top