#22266: CharField primary keys with underscores are (un)escaped differently in the admin pages ------------------------------------+-------------------- Reporter: victor.varvariuc@… | Owner: nobody Type: Bug | Status: new Component: contrib.admin | Version: 1.6 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------------+-------------------- Migrated from here: https://code.djangoproject.com/ticket/18381#comment:6
Although that bug was fixed 2 years ago, related issues seem still present in the latest stable Django release 1.6.2. CharField primary keys with underscores are (un)escaped differently in the admin pages, and when reversing admin URLs with django.core.urlresolvers.reverse() or the {% url %} template tag. The admin pages add "5F" after the underscore in when rendering URLs, but reverse() does not. As a result, links from custom pages into the admin break when the object's primary key contains underscores. Steps to reproduce: - Create a model with "id = models.CharField(max_length=100, primary_key=True)" or other similar text primary key field, - Register the model to the admin site, - Create a model instance with test_123 as the primary key, - Visit the admin, and observe admin URLs: they are of the format "/admin/<app>/<model>/test_5F123/" - Open the shell, and call reverse('admin:app_model_delete', args=['test_123']) - The URLs returned are of the format "/admin/<app>/<model>/test_123/" - no 5F - As a result, if these links are embedded in pages, they don't work - the admin page tries to decode the primary key, expects 5F, and does not find the object. {{{ [trains] vic@vic ~/projects/trains (master *) $ ./manage.py shell Python 3.3.2+ (default, Oct 9 2013, 14:50:09) >>> from django.core.urlresolvers import reverse >>> reverse('admin:trains_route_change', args=('test_123',)) >>> '/trains/route/test_123/' }}} -- Ticket URL: <https://code.djangoproject.com/ticket/22266> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.6f349640f1d9d38fe1b19114c1d2028c%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.