Opened 8 years ago

Closed 3 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

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 guettli 7 years ago.
6170.diff (2.2 KB) - added by dgouldin 3 years ago.

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by guettli

comment:1 Changed 7 years ago by guettli

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

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

  • Severity set to Normal
  • Type set to Bug

comment:4 Changed 4 years ago by julien

  • Easy pickings unset
  • Needs tests set

comment:5 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

Changed 3 years ago by dgouldin

comment:6 Changed 3 years ago by dgouldin

  • 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 3 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

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

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

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