Skip to content

Weird behavior when using a subdomain and doing a request from another host on tests #4017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Apr 25, 2018

This is more an issue report that a PR. I'm doing this because I think is easier to show what's happening and get help since I'm not sure why is this happening :/.

When @override_settings(USE_SUBDOMAIN=True) and self.client.get('/projects/sub_alias/', HTTP_HOST='pip.readthedocs.org') is used, the reverse function fails (throw an exception). After doing the same request without the HTTP_HOST header, everything is back to normal.

Note that this behavior isn't just happening inside this test, but on all tests after this one (see #3913 (comment)). You can tests this, by adding a tests case that uses the reverse function after the ResolverBase

class TestClass(TestCase):

    def test_other_test(self):
        reverse('project-sync-versions', args=[1])

I think maybe this is related to the custom resolver that keeps a state between each test case.

@stsewd
Copy link
Member Author

stsewd commented Apr 26, 2018

I just found the problem.

When the request is made inside that test, django overrides the url_conf (readthedocs.core.urls.subdomain) for the current thread! https://docs.djangoproject.com/en/1.9/_modules/django/core/urlresolvers/ (set_urlconf). So, all tests are running in that thread with that configuration, till the value get's override (to readthedocs.urls) doing another request without the HTTP_HOST header.

So, is this a bug on django or on the rtd code? This can be fixed by calling a method on the teardown method, but still, is kind of hacky.

@stsewd stsewd force-pushed the weird-behavior-test-subprojects branch from 04ff929 to 314f631 Compare April 26, 2018 21:15
@stsewd
Copy link
Member Author

stsewd commented Apr 26, 2018

The commit 314f631 should have failed on travis... You can check the tests locally, commenting out the teardown part and running tox -e py36 readthedocs/rtd_tests/tests/test_subprojects.py.

@stsewd
Copy link
Member Author

stsewd commented Apr 26, 2018

Closing this PR and opening a different one having the relevant changes only

@stsewd stsewd closed this Apr 26, 2018
@stsewd stsewd deleted the weird-behavior-test-subprojects branch April 27, 2018 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant