mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Added explicit thread safety
This commit is contained in:
parent
6b7b154034
commit
8c29d9a44d
1 changed files with 2 additions and 2 deletions
|
|
@ -93,7 +93,7 @@ class DatabaseBackend(Backend):
|
|||
if self._cache:
|
||||
value = await self._cache.aget(prefixed_key)
|
||||
if value is None:
|
||||
await sync_to_async(self.autofill)()
|
||||
await sync_to_async(self.autofill, thread_sensitive=True)()
|
||||
value = await self._cache.aget(prefixed_key)
|
||||
if value is None:
|
||||
match = await self._model._default_manager.filter(key=prefixed_key).only("value").afirst()
|
||||
|
|
@ -164,7 +164,7 @@ class DatabaseBackend(Backend):
|
|||
|
||||
# We use sync_to_async because Django's transaction.atomic() and database connections are thread-local.
|
||||
# This ensures the operation runs in the correct database thread until native async transactions are supported.
|
||||
return await sync_to_async(self.set)(key, value)
|
||||
return await sync_to_async(self.set, thread_sensitive=True)(key, value)
|
||||
|
||||
def clear(self, sender, instance, created, **kwargs):
|
||||
if self._cache and not created:
|
||||
|
|
|
|||
Loading…
Reference in a new issue