Ticket #16674: wsgi-expose-exc-info-v2.patch
File wsgi-expose-exc-info-v2.patch, 2.3 KB (added by , 13 years ago) |
---|
-
django/core/handlers/wsgi.py
139 139 content_length = 0 140 140 self._stream = LimitedStream(self.environ['wsgi.input'], content_length) 141 141 self._read_started = False 142 self._wsgi_exc_info = None 142 143 143 144 def get_full_path(self): 144 145 # RFC 3986 requires query string arguments to be in the ASCII range. … … 215 216 216 217 set_script_prefix(base.get_script_name(environ)) 217 218 signals.request_started.send(sender=self.__class__) 219 exc_info = None 218 220 try: 219 221 try: 220 222 request = self.request_class(environ) 221 223 except UnicodeDecodeError: 224 exc_info = sys.exc_info() 222 225 logger.warning('Bad Request (UnicodeDecodeError)', 223 exc_info= sys.exc_info(),226 exc_info=exc_info, 224 227 extra={ 225 228 'status_code': 400, 226 229 } 227 230 ) 228 231 response = http.HttpResponseBadRequest() 229 232 else: 230 response = self.get_response(request) 233 try: 234 response = self.get_response(request) 235 finally: 236 exc_info = request._wsgi_exc_info 237 request._wsgi_exc_info = None 231 238 finally: 232 239 signals.request_finished.send(sender=self.__class__) 233 240 … … 239 246 response_headers = [(str(k), str(v)) for k, v in response.items()] 240 247 for c in response.cookies.values(): 241 248 response_headers.append(('Set-Cookie', str(c.output(header='')))) 242 start_response(status, response_headers) 249 try: 250 start_response(status, response_headers, exc_info) 251 finally: 252 exc_info = None 243 253 return response 244 254 255 def handle_uncaught_exception(self, request, resolver, exc_info): 256 # Capture the exception context so we can pass it back to 257 # __call__() 258 request._wsgi_exc_info = exc_info 259 try: 260 return super(WSGIHandler, self).handle_uncaught_exception( 261 request, resolver, exc_info) 262 finally: 263 exc_info = None