mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fix #20745: Don't silence TypeError raised inside templates.
Thanks to robin for the report and claudep for the review.
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import re
|
||||
from functools import partial
|
||||
from importlib import import_module
|
||||
from inspect import getargspec
|
||||
from inspect import getargspec, getcallargs
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.context import (BaseContext, Context, RequestContext,
|
||||
@@ -788,10 +788,13 @@ class Variable(object):
|
||||
else:
|
||||
try: # method call (assuming no args required)
|
||||
current = current()
|
||||
except TypeError: # arguments *were* required
|
||||
# GOTCHA: This will also catch any TypeError
|
||||
# raised in the function itself.
|
||||
current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call
|
||||
except TypeError:
|
||||
try:
|
||||
getcallargs(current)
|
||||
except TypeError: # arguments *were* required
|
||||
current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call
|
||||
else:
|
||||
raise
|
||||
except Exception as e:
|
||||
if getattr(e, 'silent_variable_failure', False):
|
||||
current = settings.TEMPLATE_STRING_IF_INVALID
|
||||
|
||||
Reference in New Issue
Block a user