Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1551 -- Improved base handler to not lose track of important e…

…xception in case of exceptions within repr(). Thanks, Ned

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2667 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 51a6d81d72114adc3987d33451c5422eb27bf59a 1 parent 8d70ed4
Adrian Holovaty authored April 11, 2006

Showing 1 changed file with 7 additions and 4 deletions. Show diff stats Hide diff stats

  1. 11  django/core/handlers/base.py
11  django/core/handlers/base.py
... ...
@@ -1,4 +1,5 @@
1 1
 from django.utils import httpwrappers
  2
+import sys
2 3
 
3 4
 class BaseHandler:
4 5
     def __init__(self):
@@ -108,12 +109,14 @@ def get_response(self, path, request):
108 109
             if DEBUG:
109 110
                 return self.get_technical_error_response(request)
110 111
             else:
  112
+                # Get the exception info now, in case another exception is thrown later.
  113
+                exc_info = sys.exc_info()
111 114
                 subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', ''))
112 115
                 try:
113 116
                     request_repr = repr(request)
114 117
                 except:
115 118
                     request_repr = "Request repr() unavailable"
116  
-                message = "%s\n\n%s" % (self._get_traceback(), request_repr)
  119
+                message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
117 120
                 mail_admins(subject, message, fail_silently=True)
118 121
                 return self.get_friendly_error_response(request, resolver)
119 122
 
@@ -138,7 +141,7 @@ def get_technical_error_response(self, request, is404=False, exception=None):
138 141
         else:
139 142
             return debug.technical_500_response(request, *sys.exc_info())
140 143
 
141  
-    def _get_traceback(self):
  144
+    def _get_traceback(self, exc_info=None):
142 145
         "Helper function to return the traceback as a string"
143  
-        import sys, traceback
144  
-        return '\n'.join(traceback.format_exception(*sys.exc_info()))
  146
+        import traceback
  147
+        return '\n'.join(traceback.format_exception(*(exc_info or sys.exc_info())))

0 notes on commit 51a6d81

Please sign in to comment.
Something went wrong with that request. Please try again.