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)
Change History (14)
comment:1 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 15 years ago
I figured as much, but was confused by it working when a namespace wasn't specified.
Thanks!
comment:3 by , 15 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Triage Stage: | Unreviewed → Accepted |
No, there's definitely something fishy going on.
comment:4 by , 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 , 14 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
@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 '$'.
comment:6 by , 14 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 , 14 years ago
Has patch: | set |
---|---|
Version: | 1.2-beta → SVN |
Regex for namespaced RegexURLResolver wasn't getting processed.
I believe I have found a solution. Please see patch.
comment:8 by , 14 years ago
Needs tests: | set |
---|
comment:9 by , 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 , 14 years ago
Attachment: | test-reverse_namespaced_url.patch added |
---|
comment:10 by , 14 years ago
Needs tests: | unset |
---|
Added a simple regression test. Will see if I can figure out how to resolve.
by , 14 years ago
Attachment: | reverse_namespaced_url.patch added |
---|
Fix parsing url regex patterns when including namespaced urls.
comment:11 by , 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 , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
I believe this is a duplicate of #11559.
Your resolver is broken, you can't include at something ending with a $.