[1.1.X] Fixed #12594 -- Ensured that a meaningful exception is raised when the urlconf_module is None. Thanks to buriy for the report and patch.
Backport of r12854 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
917fb7c993
commit
7733895382
|
@ -172,6 +172,9 @@ class BaseHandler(object):
|
||||||
request_repr = "Request repr() unavailable"
|
request_repr = "Request repr() unavailable"
|
||||||
message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
|
message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
|
||||||
mail_admins(subject, message, fail_silently=True)
|
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.
|
# Return an HttpResponse that displays a friendly error message.
|
||||||
callback, param_dict = resolver.resolve500()
|
callback, param_dict = resolver.resolve500()
|
||||||
return callback(request, **param_dict)
|
return callback(request, **param_dict)
|
||||||
|
|
|
@ -5,3 +5,7 @@ import urlconf_inner
|
||||||
class ChangeURLconfMiddleware(object):
|
class ChangeURLconfMiddleware(object):
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
request.urlconf = urlconf_inner.__name__
|
request.urlconf = urlconf_inner.__name__
|
||||||
|
|
||||||
|
class NullChangeURLconfMiddleware(object):
|
||||||
|
def process_request(self, request):
|
||||||
|
request.urlconf = None
|
||||||
|
|
|
@ -17,6 +17,7 @@ ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.n
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404
|
from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404
|
||||||
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
@ -276,3 +277,16 @@ class RequestURLconfTests(TestCase):
|
||||||
response = self.client.get('/second_test/')
|
response = self.client.get('/second_test/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.content, 'outer:,inner:/second_test/')
|
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 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/')
|
||||||
|
|
Loading…
Reference in New Issue