citusdata / citusdata/django-multitenant
Support for async-safety through asgiref's Local
- Dominant language
- Python
- Stars
- 823
- Forks
- 126
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/jazzband/django-simple-history/blob/e368d839c981c60376cbffcdaba245b89766bff0/simple_history/models.py#LL43C1-L46C48):
```
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.
Contributor guide
Assessment
This issue has not been assessed yet.