Opened 13 years ago

Closed 12 years 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@… 13 years ago.
Report the patterns tried by reverse()
helpful_reverse_1_4.diff (800 bytes ) - added by wilfred@… 13 years ago.
updating patch to work correctly against trunk

Download all attachments as: .zip

Change History (7)

by wilfred@…, 13 years ago

Attachment: helpful_reverse.diff added

Report the patterns tried by reverse()

comment:1 by Preston Holmes, 13 years ago

Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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 by wilfred@…, 13 years ago

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

by wilfred@…, 13 years ago

Attachment: helpful_reverse_1_4.diff added

updating patch to work correctly against trunk

comment:3 by Aymeric Augustin, 12 years ago

Component: Core (Other)Core (URLs)

comment:4 by me@…, 12 years ago

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

comment:5 by Marc Tamlyn <marc.tamlyn@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 8365ed08b83591bf6d7ddb3b3cb066d8325573bb:

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

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