Opened 11 years ago

Closed 6 years ago

#6170 closed Bug (fixed)

Reverse urlresolver raises obscure exceptions on failure

Reported by: abrahamson.j@… Owned by: nobody
Component: Core (Other) Version: master
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


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

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 11 years ago.
6170.diff (2.2 KB) - added by David Gouldin 6 years ago.

Download all attachments as: .zip

Change History (10)

Changed 11 years ago by Thomas Güttler

comment:1 Changed 11 years ago by Thomas Güttler

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 Changed 10 years ago by robertpeters@…

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 Changed 8 years ago by Gabriel Hurley

Severity: Normal
Type: Bug

comment:4 Changed 7 years ago by Julien Phalip

Easy pickings: unset
Needs tests: set

comment:5 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

Changed 6 years ago by David Gouldin

Attachment: 6170.diff added

comment:6 Changed 6 years ago by David Gouldin

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 Changed 6 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:8 Changed 6 years ago by Julien Phalip <jphalip@…>

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