Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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 6 years ago.
improved_exceptions_for_reverse2.diff (1.8 KB) - added by mrts 6 years ago.
Reverse minor needless whitespace change in previous patch
improved_exceptions_for_reverse_with-args.diff (2.1 KB) - added by mrts 6 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 6 years ago.
Adding myself to AUTHORS

Download all attachments as: .zip

Change History (14)

comment:1 Changed 6 years ago by eibaan

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

#7821 has the same intention, I assume.

comment:2 Changed 6 years ago by julien

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

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 6 years ago by eibaan

  • Resolution invalid deleted
  • Status changed from closed to reopened

[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 6 years ago by mrts

Changed 6 years ago by mrts

Reverse minor needless whitespace change in previous patch

comment:4 Changed 6 years ago by mrts

  • Has patch set
  • milestone set to 1.0
  • Triage Stage changed from Unreviewed to Accepted

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 6 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from reopened to closed

Looks like a dupe of #7524.

comment:6 Changed 6 years ago by mrts

  • Resolution duplicate deleted
  • Status changed from closed to reopened

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

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

Adding myself to AUTHORS

comment:8 Changed 6 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 6 years ago by jacob

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

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

comment:10 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.