From 31bdebf0f388bd619be2271a15d8228f72ed0f56 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Fri, 27 Apr 2018 01:41:51 -0500 Subject: [PATCH] Restore urlconf on middleware on process_response --- readthedocs/core/middleware.py | 10 ++++++++++ readthedocs/rtd_tests/tests/test_subprojects.py | 1 + 2 files changed, 11 insertions(+) diff --git a/readthedocs/core/middleware.py b/readthedocs/core/middleware.py index a6034ccd047..09f0a4758a0 100644 --- a/readthedocs/core/middleware.py +++ b/readthedocs/core/middleware.py @@ -9,6 +9,7 @@ from django.contrib.sessions.middleware import SessionMiddleware from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned +from django.core.urlresolvers import set_urlconf, get_urlconf from django.http import Http404, HttpResponseBadRequest from readthedocs.core.utils import cname_to_slug @@ -53,6 +54,9 @@ def process_request(self, request): 'PRODUCTION_DOMAIN', 'readthedocs.org' ) + # Django sets the urlconf for the current thread + # so we need to set this again later. + self.current_urlconf = get_urlconf() if public_domain is None: public_domain = production_domain @@ -130,6 +134,12 @@ def process_request(self, request): # Normal request. return None + def process_response(self, request, response): + # Reset URLconf for this thread + # to the original one. + set_urlconf(self.current_urlconf) + return response + class SingleVersionMiddleware(object): diff --git a/readthedocs/rtd_tests/tests/test_subprojects.py b/readthedocs/rtd_tests/tests/test_subprojects.py index cffbdcdee48..d77b1eb12b8 100644 --- a/readthedocs/rtd_tests/tests/test_subprojects.py +++ b/readthedocs/rtd_tests/tests/test_subprojects.py @@ -192,6 +192,7 @@ def tearDown(self): # this causes errors when using the reverse function. # This method call deletes that setting. # set_urlconf(None) + pass @override_settings( PRODUCTION_DOMAIN='readthedocs.org',