refactor(caching): import redis exceptions directly in is_redis_scripting_unavailable

Its only caller runs after a Redis call raised, so redis is always installed there, the same as the sibling helpers that import it lazily without a fallback
This commit is contained in:
yucheng 2026-10-30 13:12:51 -07:00
parent 3227779577
commit 1343f38da9

View file

@ -456,10 +456,8 @@ def is_redis_timeout_failure(exc: BaseException) -> bool:
def is_redis_scripting_unavailable(exc: BaseException) -> bool:
"""True when Redis refused to run a Lua script for this client: an ACL without
``@scripting``, or ``EVAL`` renamed away."""
try:
from redis.exceptions import NoPermissionError, ResponseError
except ImportError:
return False
from redis.exceptions import NoPermissionError, ResponseError
if isinstance(exc, NoPermissionError):
return "permissions to run" in str(exc)
return isinstance(exc, ResponseError) and "unknown command" in str(exc).lower()