Skip to content

Commit 258af28

Browse files
committed
Fixed #4457 -- Corrected the handling of exceptions in the test client when the 500.html template is not available. Thanks to Chris Wager <[email protected]> for his help in tracking down this problem.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6023 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 44e6209 commit 258af28

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

django/test/client.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.core.signals import got_request_exception
1212
from django.dispatch import dispatcher
1313
from django.http import SimpleCookie, HttpRequest
14+
from django.template import TemplateDoesNotExist
1415
from django.test import signals
1516
from django.utils.functional import curry
1617
from django.utils.encoding import smart_str
@@ -165,7 +166,21 @@ def request(self, **request):
165166
# Capture exceptions created by the handler
166167
dispatcher.connect(self.store_exc_info, signal=got_request_exception)
167168

168-
response = self.handler(environ)
169+
try:
170+
response = self.handler(environ)
171+
except TemplateDoesNotExist, e:
172+
# If the view raises an exception, Django will attempt to show
173+
# the 500.html template. If that template is not available,
174+
# we should ignore the error in favor of re-raising the
175+
# underlying exception that caused the 500 error. Any other
176+
# template found to be missing during view error handling
177+
# should be reported as-is.
178+
if e.args != ('500.html',):
179+
raise
180+
181+
# Look for a signalled exception and reraise it
182+
if self.exc_info:
183+
raise self.exc_info[1], None, self.exc_info[2]
169184

170185
# Add any rendered template detail to the response
171186
# If there was only one template rendered (the most likely case),
@@ -179,10 +194,6 @@ def request(self, **request):
179194
else:
180195
setattr(response, detail, None)
181196

182-
# Look for a signalled exception and reraise it
183-
if self.exc_info:
184-
raise self.exc_info[1], None, self.exc_info[2]
185-
186197
# Update persistent cookie data
187198
if response.cookies:
188199
self.cookies.update(response.cookies)

0 commit comments

Comments
 (0)