Skip to content

Commit

Permalink
Restore urlconf on middleware on process_response
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed May 1, 2018
1 parent 904fd7c commit 31bdebf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions readthedocs/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down
1 change: 1 addition & 0 deletions readthedocs/rtd_tests/tests/test_subprojects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 31bdebf

Please sign in to comment.