Code

Opened 4 years ago

Last modified 5 months ago

#13525 assigned Bug

URL Reverser chokes on nested groups

Reported by: nickretallack Owned by: cypreess
Component: Core (URLs) Version: 1.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

## urls.py
from django.conf.urls.defaults import *
from django.http import HttpResponse

urlpatterns = patterns('',
    url(r'^export1\.(?P<format>\w+)$', lambda request: HttpResponse("THIS"), name='this'),
    url(r'^export2(\.(?P<format>\w+))?$', lambda request: HttpResponse("THAT"), name='that'),
)

## paste into python manage.py shell

from django.core.urlresolvers import reverse, resolve

# Both urls resolve
resolve('/export1.json')[0](None).content
resolve('/export2.json')[0](None).content

# These reverse
reverse('this', args=['json'])
reverse('this', kwargs={'format':'json'})

# These don't
reverse('that', args=['json'])
reverse('that', kwargs={'format':'json'})

## Shell session output

>>> from django.core.urlresolvers import reverse, resolve
>>> 
>>> # Both urls resolve
>>> resolve('/export1.json')[0](None).content
'THIS'
>>> resolve('/export2.json')[0](None).content
'THAT'
>>> 
>>> # These reverse
>>> reverse('this', args=['json'])
'/export1.json'
>>> reverse('this', kwargs={'format':'json'})
'/export1.json'
>>> 
>>> # These don't
>>> reverse('that', args=['json'])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/Cellar/python/2.6.4/lib/python2.6/site-packages/django/core/urlresolvers.py", line 350, in reverse
    *args, **kwargs)))
  File "/usr/local/Cellar/python/2.6.4/lib/python2.6/site-packages/django/core/urlresolvers.py", line 300, in reverse
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'that' with arguments '('json',)' and keyword arguments '{}' not found.

Attachments (0)

Change History (7)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I have a suspicion that this will be difficult to fix; if it can't be fixed, it should certainly be documented as a limitation.

comment:2 Changed 4 years ago by 3point2

i just bumped my head against this limitation, it would be great if there was a fix.

comment:3 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 16 months ago by aaugustin

  • Component changed from Core (Other) to Core (URLs)

comment:7 Changed 5 months ago by cypreess

  • Owner changed from nobody to cypreess
  • Status changed from new to assigned

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from cypreess to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.