#29673: Thread urlconf isn't reset after response complete
-----------------------------+------------------------------------
Reporter: tpict | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Carlton Gibson):
* version: 2.0 => master
* stage: Unreviewed => Accepted
Comment:
Hi Tom.
Thanks for the example project. It's a curious one:
{{{
(tmp-d8650c87792fd55) ~/Downloads/django-29673-test-case-master $
./manage.py test
..E.
======================================================================
ERROR: test_primary (django29673.secondary.tests.SecondaryTestCase)
Do stuff with the primary site.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/carlton/Downloads/django-29673-test-case-
master/django29673/secondary/tests.py", line 12, in test_primary
response = self.client.get(reverse("primary-site"))
File "/Users/carlton/ve/tmp-d8650c87792fd55/lib/python3.6/site-
packages/django/urls/base.py", line 90, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args,
**kwargs))
File "/Users/carlton/ve/tmp-d8650c87792fd55/lib/python3.6/site-
packages/django/urls/resolvers.py", line 622, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'primary-site' not
found. 'primary-site' is not a valid view function or pattern name.
----------------------------------------------------------------------
Ran 4 tests in 0.017s
FAILED (errors=1)
(tmp-d8650c87792fd55) ~/Downloads/django-29673-test-case-master $
./manage.py test django29673.secondary.tests.SecondaryTestCase
..
----------------------------------------------------------------------
Ran 2 tests in 0.009s
OK
}}}
The workaround you demonstrate in the
[https://github.com/tpict/django-29673-test-
case/blob/21dea785091a65f1b8bd34b13b773d385fa10c10/django29673/primary/middleware.py#L27-L33
the middleware.py file] is interesting:
{{{
# To make tests pass, comment the return statement and uncomment
this
# block:
try:
return self.get_response(request)
finally:
if getattr(request, "urlconf", None) is not None:
set_urlconf(None)
}}}
If you'd like to push this forward, that would be great. Next step I guess
I would be to bring the test case into the Django test suite in a PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/29673#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.cff4bd459ffd2b3fc06a63d9944695a1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.