Fixed #29673 -- Reset the URLconf at the end of each request.
Co-authored-by: Ross Thorne <rmwthorne@googlemail.com>
This commit is contained in:
parent
91841c77cd
commit
18098d261f
|
@ -3,6 +3,7 @@ import types
|
|||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured, MiddlewareNotUsed
|
||||
from django.core.signals import request_finished
|
||||
from django.db import connections, transaction
|
||||
from django.urls import get_resolver, set_urlconf
|
||||
from django.utils.log import log_response
|
||||
|
@ -167,3 +168,11 @@ class BaseHandler:
|
|||
if response:
|
||||
return response
|
||||
raise
|
||||
|
||||
|
||||
def reset_urlconf(sender, **kwargs):
|
||||
"""Reset the URLconf after each request is finished."""
|
||||
set_urlconf(None)
|
||||
|
||||
|
||||
request_finished.connect(reset_urlconf)
|
||||
|
|
|
@ -18,7 +18,7 @@ from django.test import SimpleTestCase, TestCase, override_settings
|
|||
from django.test.utils import override_script_prefix
|
||||
from django.urls import (
|
||||
NoReverseMatch, Resolver404, ResolverMatch, URLPattern, URLResolver,
|
||||
get_callable, get_resolver, resolve, reverse, reverse_lazy,
|
||||
get_callable, get_resolver, get_urlconf, resolve, reverse, reverse_lazy,
|
||||
)
|
||||
from django.urls.resolvers import RegexPattern
|
||||
|
||||
|
@ -1034,6 +1034,13 @@ class RequestURLconfTests(SimpleTestCase):
|
|||
self.client.get('/second_test/')
|
||||
b''.join(self.client.get('/second_test/'))
|
||||
|
||||
def test_urlconf_is_reset_after_request(self):
|
||||
"""The URLconf is reset after each request."""
|
||||
self.assertIsNone(get_urlconf())
|
||||
with override_settings(MIDDLEWARE=['%s.ChangeURLconfMiddleware' % middleware.__name__]):
|
||||
self.client.get(reverse('inner'))
|
||||
self.assertIsNone(get_urlconf())
|
||||
|
||||
|
||||
class ErrorHandlerResolutionTests(SimpleTestCase):
|
||||
"""Tests for handler400, handler404 and handler500"""
|
||||
|
|
Loading…
Reference in New Issue