Skip to content

Commit b447fde

Browse files
committed
Proxito middleware: reset to original urlconf after request
This also fixes a flaky test. We hit this before after proxito too https://github.com/readthedocs/readthedocs.org/blob/8ebded69160f495c56e2966da90bad3be2dc9f5f/readthedocs/core/middleware.py#L132-L136
1 parent e4973ea commit b447fde

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

readthedocs/proxito/middleware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from django.conf import settings
1212
from django.shortcuts import render
13+
from django.urls.base import set_urlconf
1314
from django.utils.deprecation import MiddlewareMixin
1415

1516
from readthedocs.projects.models import Domain, Project
@@ -199,6 +200,10 @@ def process_response(self, request, response): # noqa
199200
* For custom domains, check the HSTS values on the Domain object.
200201
The domain object should be saved already in request.domain.
201202
"""
203+
# Reset URLconf for this thread
204+
# to the original one.
205+
set_urlconf(None)
206+
202207
host = request.get_host().lower().split(':')[0]
203208
public_domain = settings.PUBLIC_DOMAIN.lower().split(':')[0]
204209

readthedocs/proxito/tests/test_middleware.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ def setUp(self):
242242
sys.modules['fake_urlconf'] = self.pip.proxito_urlconf
243243
set_urlconf('fake_urlconf')
244244

245-
# TODO: Figure out why this is failing in travis
246-
@pytest.mark.xfail(strict=True)
247245
def test_middleware_urlconf_subproject(self):
248246
resp = self.client.get('/subpath/subproject/testing/en/foodex.html', HTTP_HOST=self.domain)
249247
self.assertEqual(resp.status_code, 200)

0 commit comments

Comments
 (0)