Skip to content
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

Support for async-safety through asgiref's Local #176

Open
aprams opened this issue May 14, 2023 · 5 comments
Open

Support for async-safety through asgiref's Local #176

aprams opened this issue May 14, 2023 · 5 comments

Comments

@aprams
Copy link

aprams commented May 14, 2023

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.

darwing1210 added a commit to NewsAmp/django-multitenant that referenced this issue Jun 1, 2023
@arpanpreneur
Copy link
Contributor

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
Copy link
Contributor

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

@darwing1210
Copy link

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

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

@gurkanindibay
Copy link
Contributor

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

darwing1210 added a commit to NewsAmp/django-multitenant that referenced this issue Jul 12, 2023
add asgiref as test dependency

add tests for asgiref

add setting TENANT_USE_ASGIREF, updated tests
gurkanindibay added a commit that referenced this issue Sep 26, 2023
* Use asgiref when available instead of thread locals by @darwing1210  (#176)
---------
Co-authored-by: Darwing Medina <darwingjavier31@yahoo.es>
@aprams
Copy link
Author

aprams commented Feb 7, 2024

@gurkanindibay This can be closed as per fd84aee right?

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

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

No branches or pull requests

4 participants