Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed #15025 - template debug fails if there's a callable local var t…
…hat generates an exception

Thanks to Tai Lee for the patch and report, also to Don Spaulding.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15187 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
spookylukey committed Jan 13, 2011
1 parent e1ede21 commit 80f4826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions django/views/debug.py
Expand Up @@ -8,11 +8,11 @@
from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound
from django.template import (Template, Context, TemplateDoesNotExist,
TemplateSyntaxError)
from django.template.defaultfilters import force_escape, pprint
from django.utils.html import escape
from django.utils.importlib import import_module
from django.utils.encoding import smart_unicode, smart_str


HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST|SIGNATURE')

def linebreak_iter(template_source):
Expand Down Expand Up @@ -109,6 +109,9 @@ def get_traceback_html(self):
self.get_template_exception_info()

frames = self.get_traceback_frames()
for i, frame in enumerate(frames):
frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']]
frames[i] = frame

unicode_hint = ''
if issubclass(self.exc_type, UnicodeError):
Expand Down Expand Up @@ -547,7 +550,7 @@ def empty_urlconf(request):
{% for var in frame.vars|dictsort:"0" %}
<tr>
<td>{{ var.0|force_escape }}</td>
<td class="code"><pre>{{ var.1|pprint|force_escape }}</pre></td>
<td class="code"><pre>{{ var.1 }}</pre></td>
</tr>
{% endfor %}
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions tests/regressiontests/views/views.py
Expand Up @@ -36,6 +36,11 @@ def save(self, *args, **kwargs):
form_class=SlugChangingArticleForm)

def raises(request):
# Make sure that a callable that raises an exception in the stack frame's
# local vars won't hijack the technical 500 response. See:
# http://code.djangoproject.com/ticket/15025
def callable():
raise Exception
try:
raise Exception
except Exception:
Expand Down

0 comments on commit 80f4826

Please sign in to comment.