Code

Opened 4 years ago

Last modified 16 months ago

#14772 new Bug

Reversing a URL with optional arguments fails

Reported by: robhudson 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 robhudson 4 years ago.
14772.2.diff (1.9 KB) - added by robhudson 4 years ago.

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by robhudson

Changed 4 years ago by robhudson

comment:1 Changed 4 years ago by robhudson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 4 years ago by julien

  • Keywords reverse, sprintdec2010 added; reverse removed
  • milestone set to 1.3
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by anonymous

  • milestone 1.3 deleted
  • 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)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
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.