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)

14772.diff (1.9 KB ) - added by Rob Hudson 14 years ago.
14772.2.diff (1.9 KB ) - added by Rob Hudson 14 years ago.

Download all attachments as: .zip

Change History (9)

by Rob Hudson, 14 years ago

Attachment: 14772.diff added

by Rob Hudson, 14 years ago

Attachment: 14772.2.diff added

comment:1 by Rob Hudson, 14 years ago

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.

comment:2 by Julien Phalip, 14 years ago

Keywords: sprintdec2010 added
milestone: 1.3
Triage Stage: UnreviewedAccepted

comment:3 by anonymous, 14 years ago

milestone: 1.3
Severity: Normal
Type: Bug

comment:4 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by Aymeric Augustin, 12 years ago

Component: Core (Other)Core (URLs)

comment:7 by Bas Peschier, 10 years ago

Resolution: fixed
Status: newclosed

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

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