#35807: Clarify django.urls.set_urlconf scoping behaviour
-----------------------------+-----------------------------------------
     Reporter:  Enrico Zini  |                     Type:  Uncategorized
       Status:  new          |                Component:  Documentation
      Version:  5.0          |                 Severity:  Normal
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+-----------------------------------------
 `django.urls.set_urlconf`
 [https://github.com/django/django/blob/main/django/urls/base.py#L128
 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`.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35807>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701924f20d724-33d1f299-ce0a-4bf9-9e07-4af826d355fc-000000%40eu-central-1.amazonses.com.

Reply via email to