Django

Code

Ticket #8221 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

NoReverseMatch should not swallow ImportError/AttributeError

Reported by: eibaan Assigned to: nobody
Milestone: 1.0 Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

improved_exceptions_for_reverse.diff (2.0 kB) - added by mrts on 08/11/08 11:50:04.
improved_exceptions_for_reverse2.diff (1.8 kB) - added by mrts on 08/11/08 11:52:44.
Reverse minor needless whitespace change in previous patch
improved_exceptions_for_reverse_with-args.diff (2.1 kB) - added by mrts on 08/23/08 11:38:41.
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 on 08/23/08 13:06:23.
Adding myself to AUTHORS

Change History

08/11/08 04:50:52 changed by eibaan

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

#7821 has the same intention, I assume.

08/11/08 05:29:20 changed by julien

  • status changed from new to closed.
  • resolution set to invalid.

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.

08/11/08 08:22:35 changed by eibaan

  • status changed from closed to reopened.
  • resolution deleted.

[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.

08/11/08 11:50:04 changed by mrts

  • attachment improved_exceptions_for_reverse.diff added.

08/11/08 11:52:44 changed by mrts

  • attachment improved_exceptions_for_reverse2.diff added.

Reverse minor needless whitespace change in previous patch

08/11/08 11:55:05 changed by mrts

  • has_patch set to 1.
  • stage changed from Unreviewed to Accepted.
  • milestone set to 1.0.

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.

08/22/08 17:26:17 changed by ubernostrum

  • status changed from reopened to closed.
  • resolution set to duplicate.

Looks like a dupe of #7524.

08/23/08 10:46:24 changed by mrts

  • status changed from closed to reopened.
  • resolution deleted.

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

08/23/08 11:38:41 changed by mrts

  • attachment improved_exceptions_for_reverse_with-args.diff added.

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

08/23/08 11:47:32 changed 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.

08/23/08 13:06:23 changed by mrts

  • attachment improved_exceptions_for_reverse_with-args_updated-AUTHORS.diff added.

Adding myself to AUTHORS

08/26/08 06:35:48 changed 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).

08/28/08 14:05:20 changed by jacob

  • status changed from reopened to closed.
  • resolution set to fixed.

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


Add/Change #8221 (NoReverseMatch should not swallow ImportError/AttributeError)




Change Properties
Action