mirror of
https://github.com/django/django.git
synced 2025-07-06 02:39:12 +00:00
magic-removal: Fixes #1396 -- Added exception handler (and silent_variable_failure check) for edge case in descriptor lookup.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2604 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
859e652d36
commit
0d6f2f8707
@ -603,9 +603,9 @@ def resolve_variable(path, context):
|
|||||||
if path[0] in '0123456789':
|
if path[0] in '0123456789':
|
||||||
number_type = '.' in path and float or int
|
number_type = '.' in path and float or int
|
||||||
try:
|
try:
|
||||||
current = number_type(path)
|
current = number_type(path)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
current = settings.TEMPLATE_STRING_IF_INVALID
|
current = settings.TEMPLATE_STRING_IF_INVALID
|
||||||
elif path[0] in ('"', "'") and path[0] == path[-1]:
|
elif path[0] in ('"', "'") and path[0] == path[-1]:
|
||||||
current = path[1:-1]
|
current = path[1:-1]
|
||||||
else:
|
else:
|
||||||
@ -637,6 +637,11 @@ def resolve_variable(path, context):
|
|||||||
current = current[int(bits[0])]
|
current = current[int(bits[0])]
|
||||||
except (IndexError, ValueError, KeyError):
|
except (IndexError, ValueError, KeyError):
|
||||||
raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute
|
raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute
|
||||||
|
except Exception, e:
|
||||||
|
if getattr(e, 'silent_variable_failure', False):
|
||||||
|
current = settings.TEMPLATE_STRING_IF_INVALID
|
||||||
|
else:
|
||||||
|
raise
|
||||||
del bits[0]
|
del bits[0]
|
||||||
return current
|
return current
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user