#24962: Objects with primary keys containing newlines do not get links to being
edited in the admin list view
-------------------------------+------------------------------------
     Reporter:  alito          |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  contrib.admin  |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  1              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  1              |                    UI/UX:  1
-------------------------------+------------------------------------
Changes (by timgraham):

 * needs_tests:  1 => 0


Old description:

> The admin list view of an object lists each object and does a
>
> reverse('admin:%s_%s_change' % (self.opts.app_label,
> self.opts.model_name), args=(quote(pk),),
> current_app=self.model_admin.admin_site.name)
>
> to assign a change url for each one, skipping the link if the reverse
> fails. The 'quote' function there escapes a whole bunch of characters so
> as not to confuse the url pattern matcher but it forgets to escape
> newline.
>
> Therefore, a model like this:
>
> class Name(models.Model):
>    name = models.TextField(primary_key=True)
>
> with:
> n = Name('John')
> n.save()
> o = Name('Have a \n newline')
> o.save()
>
> will list a link for John, but no link for 'Have a
> newline'
>
> (The bug actually is triggered in quite a few other places in admin but
> the list view is the easiest one to see. I've attached some screenshots
> that I prepared earlier)
>
> Change is a 2-character change to quote \n as well (attached)

New description:

 The admin list view of an object lists each object and does a
 {{{
 reverse('admin:%s_%s_change' % (self.opts.app_label,
 self.opts.model_name), args=(quote(pk),),
 current_app=self.model_admin.admin_site.name)
 }}}
 to assign a change url for each one, skipping the link if the reverse
 fails. The 'quote' function there escapes a whole bunch of characters so
 as not to confuse the url pattern matcher but it forgets to escape
 newline.

 Therefore, a model like this:
 {{{
 class Name(models.Model):
    name = models.TextField(primary_key=True)
 }}}
 with:
 {{{
 n = Name('John')
 n.save()
 o = Name('Have a \n newline')
 o.save()
 }}}

 will list a link for John, but no link for 'Have a newline'

 (The bug actually is triggered in quite a few other places in admin but
 the list view is the easiest one to see. I've attached some screenshots
 that I prepared earlier)

 Change is a 2-character change to quote \n as well (attached)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24962#comment:3>
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/063.e5d555cce97aace955b9161b764ea649%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to