Permalink
Browse files

Fixed #12594 -- Ensured that a meaningful exception is raised when th…

…e 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
  • Loading branch information...
freakboy3742 committed Mar 26, 2010
1 parent 9b50ec8 commit 667ced2abcb557c1fc8feda7c4d952193b8f5768
@@ -173,6 +173,9 @@ def handle_uncaught_exception(self, request, resolver, exc_info):
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)
@@ -5,3 +5,7 @@
class ChangeURLconfMiddleware(object):
def process_request(self, request):
request.urlconf = urlconf_inner.__name__
+
+class NullChangeURLconfMiddleware(object):
+ def process_request(self, request):
+ request.urlconf = None
@@ -17,6 +17,7 @@
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 @@ def test_urlconf_overridden(self):
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 @@ def test_callable_handers(self):
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/')

0 comments on commit 667ced2

Please sign in to comment.