Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#8221 closed (fixed)

NoReverseMatch should not swallow ImportError/AttributeError

Reported by: eibaan Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In django.core.urlresolver.reverse around line 200, NoReverseMatch is raised without further details. Please provide more details to help debugging. In case of import or attribute errors, please provide the original exception and do not swallow it.

Attachments (4)

improved_exceptions_for_reverse.diff (2.0 KB) - added by mrts 8 years ago.
improved_exceptions_for_reverse2.diff (1.8 KB) - added by mrts 8 years ago.
Reverse minor needless whitespace change in previous patch
improved_exceptions_for_reverse_with-args.diff (2.1 KB) - added by mrts 8 years ago.
Make 'Reverse for foo not found' more useful by showing the arguments as well. This really helps to fix problems in real life.
improved_exceptions_for_reverse_with-args_updated-AUTHORS.diff (2.6 KB) - added by mrts 8 years ago.
Adding myself to AUTHORS

Download all attachments as: .zip

Change History (14)

comment:1 Changed 8 years ago by eibaan

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

#7821 has the same intention, I assume.

comment:2 Changed 8 years ago by Julien Phalip

Resolution: invalid
Status: newclosed

This should have been fixed in [8272]. Try with a more recent version of trunk.
If an exception is raised at that point, it's because the given view name could not be matched against the registered URLs.

Reopen this ticket if you estimate that the information given in the exception message -- basically, the unmatched view name -- is still not enough for debugging.

comment:3 Changed 8 years ago by eibaan

Resolution: invalid
Status: closedreopened

[8272] fixed two occurences of NoReverseMatch near line 291. Near line 200, there are two more occurences. Furthermore, it would be helpful to get access to the root cause (attribute or import error). I might be wrong, but "not a callable" is just a guess. For example, it could also be a syntax error in a Python file or a missing file that causes the import error.

Changed 8 years ago by mrts

Changed 8 years ago by mrts

Reverse minor needless whitespace change in previous patch

comment:4 Changed 8 years ago by mrts

Has patch: set
milestone: 1.0
Triage Stage: UnreviewedAccepted

eibaan is right, I just scratched the place where it itched when I submitted the patch that was merged in r8272. Should have looked around.

comment:5 Changed 8 years ago by James Bennett

Resolution: duplicate
Status: reopenedclosed

Looks like a dupe of #7524.

comment:6 Changed 8 years ago by mrts

Resolution: duplicate
Status: closedreopened

ubernostrum, this is a different issue than what's reported at #7524. Please look at the patch.

Changed 8 years ago by mrts

Make 'Reverse for foo not found' more useful by showing the arguments as well. This really helps to fix problems in real life.

comment:7 Changed 8 years ago by mrts

Justification for change in last patch:

in one of my projects, some articles had somehow invalid slugs (with spaces, I actually wonder how this is possible -- SlugField shouldn't allow saving these), so, of course I got 'Reverse for foo not found' for the article view. It took me a while to find out what's wrong. With this patch, I could instantly spot the problem.

Changed 8 years ago by mrts

Adding myself to AUTHORS

comment:8 Changed 8 years ago by mrts

Invalid slugs came from #8040 (fixed as late as in r8477, which means more people can be hit by exactly the same problem).

comment:9 Changed 8 years ago by Jacob

Resolution: fixed
Status: reopenedclosed

(In [8672]) Fixed #8221: added some better NoReverseMatch error strings. Thanks, mrts.

comment:10 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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