Opened 15 years ago

Closed 14 years ago

#12950 closed (duplicate)

urlresolvers.reverse returns '/$' when including namespaced '^$' pattern at root '^$'

Reported by: David Bennett Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: urlresolvers reverse namespace
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In project urls.py:

incpatterns = patterns('',
    url(r'^$', myapp.views.index, name='index'),
)
urlpatterns = patterns('',
    (r'^$', include(incpatterns, namespace='myapp')),
)
>>> reverse('myapp:index')
'/$'

It correctly returns '/' if the included pattern isn't namespaced.

Attachments (2)

test-reverse_namespaced_url.patch (1.3 KB ) - added by David Bennett 14 years ago.
reverse_namespaced_url.patch (1.1 KB ) - added by David Bennett 14 years ago.
Fix parsing url regex patterns when including namespaced urls.

Download all attachments as: .zip

Change History (14)

comment:1 by Alex Gaynor, 15 years ago

Resolution: invalid
Status: newclosed

Your resolver is broken, you can't include at something ending with a $.

comment:2 by David Bennett, 15 years ago

I figured as much, but was confused by it working when a namespace wasn't specified.

Thanks!

comment:3 by Chris Beaven, 15 years ago

Resolution: invalid
Status: closedreopened
Triage Stage: UnreviewedAccepted

No, there's definitely something fishy going on.

comment:4 by Chris Beaven, 15 years ago

Normal:

incpatterns = patterns('',
    url(r'^$', 'views.front', name='index'),
)
urlpatterns = patterns('views',
    (r'test?/', include(incpatterns)),
)

>>> reverse('index')
'/tes/

Namespaced:

incpatterns = patterns('',
    url(r'^$', 'views.front', name='index'),
)
urlpatterns = patterns('views',
    (r'test?/', include(incpatterns, namespace='myapp')),
)

>>> reverse('myapp:index')
'/test?/

comment:5 by v1v3kn, 14 years ago

Resolution: invalid
Status: reopenedclosed

@SmileyChris

This is not really a bug, this is due to the way the '?' quantifier works.

'?' matches the character preceding it zero or one time(s).
Eg: the regex pattern 'cows' matches both 'cow' and 'cows'.

And as Alex said earlier, you can't include anything after a '$'.

Version 0, edited 14 years ago by v1v3kn (next)

comment:6 by Chris Beaven, 14 years ago

Resolution: invalid
Status: closedreopened

Perhaps you misread my example code. I didn't include anything after a '$'.

And I understand how quantifiers work. The issue here is that a namespaced app isn't processing the regular expression question mark as expected.

I haven't actually retested my code, but your reasoning for closing doesn't show that you did either so I'll reopen.

comment:7 by David Bennett, 14 years ago

Has patch: set
Version: 1.2-betaSVN

Regex for namespaced RegexURLResolver wasn't getting processed.

I believe I have found a solution. Please see patch.

comment:8 by Łukasz Rekucki, 14 years ago

Needs tests: set

comment:9 by David Bennett, 14 years ago

Patch needs improvement: set

Hadn't run tests on my patch. They break.

Will do some more digging and add a regression test for this.

by David Bennett, 14 years ago

comment:10 by David Bennett, 14 years ago

Needs tests: unset

Added a simple regression test. Will see if I can figure out how to resolve.

by David Bennett, 14 years ago

Fix parsing url regex patterns when including namespaced urls.

comment:11 by David Bennett, 14 years ago

Patch needs improvement: unset

New patch passes tests.

What patch does is copy namespaced resolver into non-namespace resolver, then wraps with root resolver so that everything works.

comment:12 by Carl Meyer, 14 years ago

Resolution: duplicate
Status: reopenedclosed

I believe this is a duplicate of #11559.

Note: See TracTickets for help on using tickets.
Back to Top