From 258af283fc398ff99c2de9386b494eb1910e2d74 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 28 Aug 2007 13:03:22 +0000 Subject: [PATCH] Fixed #4457 -- Corrected the handling of exceptions in the test client when the 500.html template is not available. Thanks to Chris Wager for his help in tracking down this problem. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6023 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/test/client.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/django/test/client.py b/django/test/client.py index 9ec3615973..12753d2eac 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -11,6 +11,7 @@ from django.core.handlers.wsgi import WSGIRequest from django.core.signals import got_request_exception from django.dispatch import dispatcher from django.http import SimpleCookie, HttpRequest +from django.template import TemplateDoesNotExist from django.test import signals from django.utils.functional import curry from django.utils.encoding import smart_str @@ -165,7 +166,21 @@ class Client: # Capture exceptions created by the handler dispatcher.connect(self.store_exc_info, signal=got_request_exception) - response = self.handler(environ) + try: + response = self.handler(environ) + except TemplateDoesNotExist, e: + # If the view raises an exception, Django will attempt to show + # the 500.html template. If that template is not available, + # we should ignore the error in favor of re-raising the + # underlying exception that caused the 500 error. Any other + # template found to be missing during view error handling + # should be reported as-is. + if e.args != ('500.html',): + raise + + # Look for a signalled exception and reraise it + if self.exc_info: + raise self.exc_info[1], None, self.exc_info[2] # Add any rendered template detail to the response # If there was only one template rendered (the most likely case), @@ -179,10 +194,6 @@ class Client: else: setattr(response, detail, None) - # Look for a signalled exception and reraise it - if self.exc_info: - raise self.exc_info[1], None, self.exc_info[2] - # Update persistent cookie data if response.cookies: self.cookies.update(response.cookies)