From 667ced2abcb557c1fc8feda7c4d952193b8f5768 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 26 Mar 2010 15:08:24 +0000 Subject: [PATCH] Fixed #12594 -- Ensured that a meaningful exception is raised when the urlconf_module is None. Thanks to buriy for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12854 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/handlers/base.py | 3 +++ .../urlpatterns_reverse/middleware.py | 4 ++++ .../urlpatterns_reverse/tests.py | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index dac0adfb93..79f6607214 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 7bb9aa924f..cd3c045159 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 d5f3ec9546..3fcc935da2 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/')