Fix: if redis is not configured do not enable rate limit (#2027)

This commit is contained in:
Adrià Casajús 2024-02-05 14:53:01 +01:00 committed by GitHub
parent 30aaf118e7
commit 4a7c0293f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -23,9 +23,11 @@ def check_bucket_limit(
# Calculate current bucket time
bucket_id = int(datetime.utcnow().timestamp()) % bucket_seconds
bucket_lock_name = f"bl:{lock_name}:{bucket_id}"
if not lock_redis:
return
try:
value = lock_redis.incr(bucket_lock_name, bucket_seconds)
if value > max_hits:
raise werkzeug.exceptions.TooManyRequests()
except redis.exceptions.RedisError:
except (redis.exceptions.RedisError, AttributeError):
log.e("Cannot connect to redis")