Code

Opened 2 years ago

Closed 10 months ago

#17076 closed Cleanup/optimization (fixed)

Report the number of patterns tried when reversing

Reported by: wilfred@… Owned by: nobody
Component: Core (URLs) Version: 1.3
Severity: Normal Keywords: reverse
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Relevant django-dev discussion: http://groups.google.com/group/django-developers/browse_thread/thread/d3bcc13fff8d7320

It would be great to know which patterns were tested when NoReverseMatch is thrown. This would help distinguish between "I've typed the URL name incorrectly" and "I've missed a keyword argument for this URL".

Patch attached, I would welcome feedback.

The current patch produces the following exception if the URL name is wrong:

NoReverseMatch: Reverse for 'incorrect_url_name' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

And the following exception if a keyword argument is missing:

NoReverseMatch: Reverse for 'needs_exactly_one_kwargs' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['user/(?P<user_id>\\d+)/update/$']

Attachments (2)

helpful_reverse.diff (790 bytes) - added by wilfred@… 2 years ago.
Report the patterns tried by reverse()
helpful_reverse_1_4.diff (800 bytes) - added by wilfred@… 2 years ago.
updating patch to work correctly against trunk

Download all attachments as: .zip

Change History (7)

Changed 2 years ago by wilfred@…

Report the patterns tried by reverse()

comment:1 Changed 2 years ago by ptone

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

I think your list comprehension statement needs some work based on this:

https://github.com/django/django/blob/master/django/core/urlresolvers.py#L361

comment:2 Changed 2 years ago by wilfred@…

Cripes, I must have tested on an older version. Sorry about that. Here's an updated patch.

Changed 2 years ago by wilfred@…

updating patch to work correctly against trunk

comment:3 Changed 13 months ago by aaugustin

  • Component changed from Core (Other) to Core (URLs)

comment:4 Changed 10 months ago by me@…

I've opened a pull request against trunk on GitHub, with a unit test. See https://github.com/django/django/pull/1266 .

comment:5 Changed 10 months ago by Marc Tamlyn <marc.tamlyn@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 8365ed08b83591bf6d7ddb3b3cb066d8325573bb:

Fixed #17076 -- When reversing a URL fails, inform the user which patterns were tried.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.