django-multitenant icon indicating copy to clipboard operation
django-multitenant copied to clipboard

Support for async-safety through asgiref's Local

Open aprams opened this issue 2 years ago • 5 comments

We are looking to switch to ASGI soon and are freshly using django-multitenant as well. As the threading.local is being used by django-multitenant, I'm afraid of cross-request tenant leakages. I therefore suggest an approach similar to django-simple-history:

try:
    from asgiref.local import Local as LocalContext
except ImportError:
    from threading import local as LocalContext

This should use asgiref's Local as an asgi-safe alternative to threading.locals as per my understanding. As asgiref.local is meant as a drop-in replacement, the change should be straightforward.

aprams avatar May 14 '23 12:05 aprams

Yes, even I wanted to understand if django-multitenant is compatible with ASGI and Channels server. I am new to Channels and ASGI, so need some advice before I port my current Django app which uses this library into an ASGI mode for some of the new features.

arpanpreneur avatar Jun 23 '23 14:06 arpanpreneur

@darwing1210 Do we have an eta when this can be released?

arpanpreneur avatar Jun 29 '23 11:06 arpanpreneur

@darwing1210 Do we have an eta when this can be released?

I'm not sure, as it was never reviewed by the repo owners

darwing1210 avatar Jun 29 '23 12:06 darwing1210

Hey @darwing1210 @arpanpreneur I'm reviewing right now. Thanks for your contributions

gurkanindibay avatar Jul 11 '23 11:07 gurkanindibay

@gurkanindibay This can be closed as per https://github.com/citusdata/django-multitenant/commit/fd84aeee9f71f66775a5f4256102f9010418a940 right?

Thanks for the contributions - amazing project, thanks a lot! :)

aprams avatar Feb 07 '24 18:02 aprams