Improved fix for #18373 -- backward compatibility
Commit 79558c78
cleaned up the (undocumented) interface of Resolver404
exception, which breaks compatibility with code messing with .args[0]
directly. Revert the cleanup part and simply leave the fix itself.
This commit is contained in:
parent
d0133504e5
commit
0b6f9f7c6f
|
@ -69,11 +69,8 @@ class ResolverMatch(object):
|
||||||
|
|
||||||
|
|
||||||
class Resolver404(Http404):
|
class Resolver404(Http404):
|
||||||
|
pass
|
||||||
|
|
||||||
def __init__(self, path, tried=None):
|
|
||||||
super(Resolver404, self).__init__()
|
|
||||||
self.path = path
|
|
||||||
self.tried = tried
|
|
||||||
|
|
||||||
|
|
||||||
class NoReverseMatch(Exception):
|
class NoReverseMatch(Exception):
|
||||||
|
@ -326,7 +323,7 @@ class RegexURLResolver(LocaleRegexProvider):
|
||||||
try:
|
try:
|
||||||
sub_match = pattern.resolve(new_path)
|
sub_match = pattern.resolve(new_path)
|
||||||
except Resolver404 as e:
|
except Resolver404 as e:
|
||||||
sub_tried = e.tried
|
sub_tried = e.args[0].get('tried')
|
||||||
if sub_tried is not None:
|
if sub_tried is not None:
|
||||||
tried.extend([pattern] + t for t in sub_tried)
|
tried.extend([pattern] + t for t in sub_tried)
|
||||||
else:
|
else:
|
||||||
|
@ -337,8 +334,8 @@ class RegexURLResolver(LocaleRegexProvider):
|
||||||
sub_match_dict.update(sub_match.kwargs)
|
sub_match_dict.update(sub_match.kwargs)
|
||||||
return ResolverMatch(sub_match.func, sub_match.args, sub_match_dict, sub_match.url_name, self.app_name or sub_match.app_name, [self.namespace] + sub_match.namespaces)
|
return ResolverMatch(sub_match.func, sub_match.args, sub_match_dict, sub_match.url_name, self.app_name or sub_match.app_name, [self.namespace] + sub_match.namespaces)
|
||||||
tried.append([pattern])
|
tried.append([pattern])
|
||||||
raise Resolver404(new_path, tried=tried)
|
raise Resolver404({'tried': tried, 'path': new_path})
|
||||||
raise Resolver404(path)
|
raise Resolver404({'path': path})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def urlconf_module(self):
|
def urlconf_module(self):
|
||||||
|
|
|
@ -475,11 +475,14 @@ class ExceptionReporter(object):
|
||||||
def technical_404_response(request, exception):
|
def technical_404_response(request, exception):
|
||||||
"Create a technical 404 error response. The exception should be the Http404."
|
"Create a technical 404 error response. The exception should be the Http404."
|
||||||
try:
|
try:
|
||||||
tried = exception.tried
|
error_url = exception.args[0]['path']
|
||||||
error_url = exception.path
|
except (IndexError, TypeError, KeyError):
|
||||||
except AttributeError:
|
error_url = request.path_info[1:] # Trim leading slash
|
||||||
|
|
||||||
|
try:
|
||||||
|
tried = exception.args[0]['tried']
|
||||||
|
except (IndexError, TypeError, KeyError):
|
||||||
tried = []
|
tried = []
|
||||||
error_url = request.path_info[1:] # Trim leading slash
|
|
||||||
else:
|
else:
|
||||||
if (not tried # empty URLconf
|
if (not tried # empty URLconf
|
||||||
or (request.path == '/'
|
or (request.path == '/'
|
||||||
|
|
|
@ -272,10 +272,10 @@ class ResolverTests(unittest.TestCase):
|
||||||
self.fail('resolve did not raise a 404')
|
self.fail('resolve did not raise a 404')
|
||||||
except Resolver404 as e:
|
except Resolver404 as e:
|
||||||
# make sure we at least matched the root ('/') url resolver:
|
# make sure we at least matched the root ('/') url resolver:
|
||||||
self.assertTrue(hasattr(e, 'tried'))
|
self.assertTrue('tried' in e.args[0])
|
||||||
tried = e.tried
|
tried = e.args[0]['tried']
|
||||||
self.assertEqual(len(tried), len(url_types_names), 'Wrong number of tried URLs returned. Expected %s, got %s.' % (len(url_types_names), len(tried)))
|
self.assertEqual(len(e.args[0]['tried']), len(url_types_names), 'Wrong number of tried URLs returned. Expected %s, got %s.' % (len(url_types_names), len(e.args[0]['tried'])))
|
||||||
for tried, expected in zip(tried, url_types_names):
|
for tried, expected in zip(e.args[0]['tried'], url_types_names):
|
||||||
for t, e in zip(tried, expected):
|
for t, e in zip(tried, expected):
|
||||||
self.assertIsInstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type'])
|
self.assertIsInstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type'])
|
||||||
if 'name' in e:
|
if 'name' in e:
|
||||||
|
|
Loading…
Reference in New Issue