Opened 6 hours ago
#35807 new Uncategorized
Clarify django.urls.set_urlconf scoping behaviour
Reported by: | Enrico Zini | Owned by: | |
---|---|---|---|
Component: | Documentation | Version: | 5.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
django.urls.set_urlconf
docstring mentions setting the urlconf for the current thread. However, this is backed by asgiref.local.Local
, which is supposed to provide scoping features related to asyncio tasks as well. This becomes relevant, for example, when doing multi-tenancy with more than one urlconf and trying to call django.urls.reverse
in an ASGI application.
I have been trying to infer what is the expected behaviour in async Django code by following the current implementation, and I found that asgiref.local.Local
behaviour has changed over time (see https://github.com/django/asgiref/issues/473).
I assume that using asgiref.local.Local
instead of threading.local
hints at an intention is to give set_urlconf
/get_urlconf
meaningful semantics for Channels consumers or ASGI applications.
Whether the intention is to isolate set_urlconf
/get_urlconf
across different asyncio tasks or to only support isolation between threads, I suppose it would be useful if their behaviour was documented also for the case of asyncio code, especially given they back django.urls.reverse
.