Opened 17 years ago

Closed 12 years ago

#6170 closed Bug (fixed)

Reverse urlresolver raises obscure exceptions on failure

Reported by: abrahamson.j@… Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords: reverse urls exception 'unbalanced parenthesis'
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Related to ticket #2977.

When reverse fails to reverse a complex regex obscure errors can be raised. For instance, reversing the url r'^(\d(\d)?)/$' causes an 'unbalanced parenthesis' to be raised from re.py._compile.

The urlresolver is clearly in flux right now; however, this error could be very difficult for someone new to Django (read, me) to understand. Better exception catching that notifies when a url isn't supported by reverse would be very helpful.

Attachments (2)

core_urlresovlers__better_error_message.diff (970 bytes ) - added by Thomas Güttler 17 years ago.
6170.diff (2.2 KB ) - added by David Gouldin 12 years ago.

Download all attachments as: .zip

Change History (10)

by Thomas Güttler, 17 years ago

comment:1 by Thomas Güttler, 17 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

I wrote a small patch to give a better error message. I remember, that I had this problem some time ago, too.

comment:2 by robertpeters@…, 16 years ago

I have never participated in a bug tracker before, but if it weren't for this ticket, I never would have figured out what was wrong. I vote for the new code to be added. It would have pointed me to the right place to fix my problem immediately.

comment:3 by Gabriel Hurley, 14 years ago

Severity: Normal
Type: Bug

comment:4 by Julien Phalip, 14 years ago

Easy pickings: unset
Needs tests: set

comment:5 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

by David Gouldin, 12 years ago

Attachment: 6170.diff added

comment:6 by David Gouldin, 12 years ago

Needs tests: unset

The original patch no longer made sense, so I wrote a new one and added a test. ImproperlyConfigured is probably a more descriptive exception for this issue than NoReverseMatch.

comment:7 by Jannis Leidel, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Julien Phalip <jphalip@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [1af0271d7c6f5ecda2247a2b363d25f493c7b05a]:

Fixed #6170 -- Ensured that a useful exception is raised when a regex is invalid in the URLConf.
Thanks to abrahamson.j for the report, to guettli for initial work on the patch, and to David Gouldin for the new patch and test.

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