Code

Ticket #8221: improved_exceptions_for_reverse2.diff

File improved_exceptions_for_reverse2.diff, 1.8 KB (added by mrts, 6 years ago)

Reverse minor needless whitespace change in previous patch

Line 
1Index: django/core/urlresolvers.py
2===================================================================
3--- django/core/urlresolvers.py (revision 8305)
4+++ django/core/urlresolvers.py (working copy)
5@@ -52,6 +52,9 @@
6             mod_name, func_name = get_mod_func(lookup_view)
7             if func_name != '':
8                 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
9+                if not callable(lookup_view):
10+                    raise AttributeError("'%s' in module '%s' is not a callable."
11+                            % (func_name, mod_name))
12         except (ImportError, AttributeError):
13             if not can_fail:
14                 raise
15@@ -197,9 +200,9 @@
16         try:
17             lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
18         except (ImportError, AttributeError):
19-            raise NoReverseMatch
20+            raise NoReverseMatch("Error importing '%s': %s." % (viewname, e))
21         if lookup_view != self.callback:
22-            raise NoReverseMatch
23+            raise NoReverseMatch("Imported '%s' doesn't match the expected function." % viewname)
24         return self.reverse_helper(*args, **kwargs)
25 
26     def reverse_helper(self, *args, **kwargs):
27@@ -284,8 +287,8 @@
28     def reverse(self, lookup_view, *args, **kwargs):
29         try:
30             lookup_view = get_callable(lookup_view, True)
31-        except (ImportError, AttributeError):
32-            raise NoReverseMatch("'%s' is not a callable." % lookup_view)
33+        except (ImportError, AttributeError), e:
34+            raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
35         if lookup_view in self.reverse_dict:
36             return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
37         raise NoReverseMatch("Reverse for '%s' not found." % lookup_view)