From 0d6f2f87072f75e9ca8bacc2dfd9e64f245a809a Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 1 Apr 2006 03:14:35 +0000 Subject: [PATCH] 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 --- django/template/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django/template/__init__.py b/django/template/__init__.py index 0644f758f3..26c6b784ae 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -603,9 +603,9 @@ def resolve_variable(path, context): if path[0] in '0123456789': number_type = '.' in path and float or int try: - current = number_type(path) + current = number_type(path) except ValueError: - current = settings.TEMPLATE_STRING_IF_INVALID + current = settings.TEMPLATE_STRING_IF_INVALID elif path[0] in ('"', "'") and path[0] == path[-1]: current = path[1:-1] else: @@ -637,6 +637,11 @@ def resolve_variable(path, context): current = current[int(bits[0])] except (IndexError, ValueError, KeyError): 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] return current