diff --git a/weblate/utils/lock.py b/weblate/utils/lock.py index 5704bf952b69..05aa5ed87fb4 100644 --- a/weblate/utils/lock.py +++ b/weblate/utils/lock.py @@ -6,9 +6,11 @@ import os from contextlib import suppress +from typing import cast import sentry_sdk from django.core.cache import cache +from django_redis.cache import RedisCache from filelock import FileLock, Timeout from redis_lock import AlreadyAcquired, NotAcquired @@ -29,7 +31,7 @@ def __init__( key: int, slug: str, cache_template: str = "lock:{scope}:{key}", - file_template: str | None = "{slug}-{scope}.lock", + file_template: str = "{slug}-{scope}.lock", timeout: int = 1, ) -> None: self._timeout = timeout @@ -41,7 +43,7 @@ def __init__( if is_redis_cache(): # Prefer Redis locking as it works distributed self._name = self._format_template(cache_template) - self._lock = cache.lock( + self._lock = cast(RedisCache, cache).lock( key=self._name, expire=3600, auto_renewal=True,