Author: russellm
Date: 2007-08-28 08:03:22 -0500 (Tue, 28 Aug 2007)
New Revision: 6023

Modified:
   django/trunk/django/test/client.py
Log:
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.


Modified: django/trunk/django/test/client.py
===================================================================
--- django/trunk/django/test/client.py  2007-08-27 00:30:37 UTC (rev 6022)
+++ django/trunk/django/test/client.py  2007-08-28 13:03:22 UTC (rev 6023)
@@ -11,6 +11,7 @@
 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,8 +166,22 @@
         # 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),
         # flatten the list to a single element
@@ -179,10 +194,6 @@
             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)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to