diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index dac0adfb93c..79f6607214d 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -173,6 +173,9 @@ class BaseHandler(object): request_repr = "Request repr() unavailable" message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) mail_admins(subject, message, fail_silently=True) + # If Http500 handler is not installed, re-raise last exception + if resolver.urlconf_module is None: + raise exc_info[1], None, exc_info[2] # Return an HttpResponse that displays a friendly error message. callback, param_dict = resolver.resolve500() return callback(request, **param_dict) diff --git a/tests/regressiontests/urlpatterns_reverse/middleware.py b/tests/regressiontests/urlpatterns_reverse/middleware.py index 7bb9aa924f1..cd3c0451598 100644 --- a/tests/regressiontests/urlpatterns_reverse/middleware.py +++ b/tests/regressiontests/urlpatterns_reverse/middleware.py @@ -5,3 +5,7 @@ import urlconf_inner class ChangeURLconfMiddleware(object): def process_request(self, request): request.urlconf = urlconf_inner.__name__ + +class NullChangeURLconfMiddleware(object): + def process_request(self, request): + request.urlconf = None diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py index d5f3ec95465..3fcc935da2f 100644 --- a/tests/regressiontests/urlpatterns_reverse/tests.py +++ b/tests/regressiontests/urlpatterns_reverse/tests.py @@ -17,6 +17,7 @@ ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.n import unittest from django.conf import settings +from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404 from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect from django.shortcuts import redirect @@ -282,16 +283,22 @@ class RequestURLconfTests(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'outer:,inner:/second_test/') + def test_urlconf_overridden_with_null(self): + settings.MIDDLEWARE_CLASSES += ( + '%s.NullChangeURLconfMiddleware' % middleware.__name__, + ) + self.assertRaises(ImproperlyConfigured, self.client.get, '/test/me/') + class ErrorHandlerResolutionTests(TestCase): """Tests for handler404 and handler500""" - + def setUp(self): from django.core.urlresolvers import RegexURLResolver urlconf = 'regressiontests.urlpatterns_reverse.urls_error_handlers' urlconf_callables = 'regressiontests.urlpatterns_reverse.urls_error_handlers_callables' self.resolver = RegexURLResolver(r'^$', urlconf) self.callable_resolver = RegexURLResolver(r'^$', urlconf_callables) - + def test_named_handlers(self): from views import empty_view handler = (empty_view, {}) @@ -303,3 +310,10 @@ class ErrorHandlerResolutionTests(TestCase): handler = (empty_view, {}) self.assertEqual(self.callable_resolver.resolve404(), handler) self.assertEqual(self.callable_resolver.resolve500(), handler) + +class NoRootUrlConfTests(TestCase): + """Tests for handler404 and handler500 if urlconf is None""" + urls = None + + def test_no_handler_exception(self): + self.assertRaises(ImproperlyConfigured, self.client.get, '/test/me/')