Ticket #20752: 20752_patch.diff

File 20752_patch.diff, 3.3 KB (added by schacki, 11 years ago)
  • django/core/handlers/base.py

    diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
    index 9679ae8..20a6a10 100644
    a b class BaseHandler(object):  
    191191
    192192        except: # Handle everything else.
    193193            # Get the exception info now, in case another exception is thrown later.
    194             signals.got_request_exception.send(sender=self.__class__, request=request)
    195             response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
     194            exc_info = sys.exc_info()
     195            signal_responses = signals.got_request_exception.send_robust(sender=self.__class__, request=request)
     196            for signal_response in signal_responses:
     197                if isinstance(signal_response[1], Exception):
     198                    message = 'Base Handler Error %s: ' % signal_response[1]
     199                    logger.error(message+'%s', request.path,
     200                        exc_info=exc_info,
     201                        extra={
     202                            'status_code': 500,
     203                            'request': request,
     204                            'error': signal_response[1]
     205                        }
     206                    )
     207            response = self.handle_uncaught_exception(request, resolver, exc_info)
    196208
    197209        try:
    198210            # Apply response middleware, regardless of the response
  • tests/view_tests/tests/test_defaults.py

    diff --git a/tests/view_tests/tests/test_defaults.py b/tests/view_tests/tests/test_defaults.py
    index d55ed53..7a74b0b 100644
    a b  
    11from __future__ import unicode_literals
    22
     3import logging
     4
     5from django.utils.six import StringIO
     6
     7from django.core.signals import got_request_exception
     8from django.dispatch import receiver
    39from django.contrib.contenttypes.models import ContentType
     10
    411from django.test import TestCase
    512from django.test.utils import (setup_test_template_loader,
    6     restore_template_loaders, override_settings)
     13    restore_template_loaders, override_settings, patch_logger)
    714
    815from ..models import Author, Article, UrlArticle
    916
    class DefaultsTests(TestCase):  
    3340
    3441    def test_server_error(self):
    3542        "The server_error view raises a 500 status"
    36         response = self.client.get('/views/server_error/')
    37         self.assertEqual(response.status_code, 500)
     43        with self.settings(DEBUG=True):
     44            with patch_logger('django.request', 'error') as calls:
     45                response = self.client.get('/views/server_error/')
     46                self.assertEqual(response.status_code, 500)
     47                self.assertEqual(len(calls), 1)       
     48
     49    def test_server_error_with_handler_error(self):
     50        """
     51        The server_error view raises a 500 status and while handling
     52        the error, the next error is raised.
     53        """
     54
     55        @receiver(got_request_exception)
     56        def handler(sender, **kwargs):
     57            raise Exception('I am a Handler Error')
     58
     59        with self.settings(DEBUG=True):
     60            with patch_logger('django.request', 'error') as calls:
     61                response = self.client.get('/views/server_error/')
     62                self.assertEqual(response.status_code, 500)
     63                self.assertEqual(len(calls), 2)
    3864
    3965    def test_custom_templates(self):
    4066        """
Back to Top