Opened 14 years ago
Closed 10 years ago
#14772 closed Bug (fixed)
Reversing a URL with optional arguments fails
Reported by: | Rob Hudson | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 1.2 |
Severity: | Normal | Keywords: | reverse, sprintdec2010 |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I discovered this recently where I wanted a URL to be /detail/ for page 1, and /detail/page-2/ for further pages. I set up the "page-2/" as an optional regular expression and my default had a default kwarg. Reversing this URL without the page worked but not when I added the page argument. So I created some test cases and found some interesting results...
The first test case without the '$' terminated URL, results in:
AssertionError: '/optional/1/2' != '/optional/1/2/'
With the '$' terminated URL, it results in an exception, which is what I was triggering in my project, it seems:
AssertionError: '/optional/1/2/' != <class 'django.core.urlresolvers.NoReverseMatch'>
I'll attach the testing changes...
Attachments (2)
Change History (9)
by , 14 years ago
Attachment: | 14772.diff added |
---|
by , 14 years ago
Attachment: | 14772.2.diff added |
---|
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Keywords: | sprintdec2010 added |
---|---|
milestone: | → 1.3 |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 14 years ago
milestone: | 1.3 |
---|---|
Severity: | → Normal |
Type: | → Bug |
comment:6 by , 12 years ago
Component: | Core (Other) → Core (URLs) |
---|
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The reason the tests failed with the slash inside the capturing group was that you should add the slash to the group in the reverse args/kwargs.
The second patch runs smoothly against master, probably fixed somewhere between then and now.
I am including the tests as part of the tests/documentation of #13525
The 2nd patch moves the trailing slash out of the named group and the added tests now pass. I'm attaching if these extra tests are something that might be added to the resolving tests.