mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(proxy): don't import redis.asyncio on startup when transaction buffer is disabled
This commit is contained in:
parent
e84a19acd5
commit
cd7c8e4041
2 changed files with 16 additions and 1 deletions
|
|
@ -7277,7 +7277,6 @@ class ProxyStartupEvent:
|
|||
Returns None when the buffer is disabled, or when no Redis host or url
|
||||
is set in the environment.
|
||||
"""
|
||||
from litellm._redis import _redis_kwargs_from_environment
|
||||
from litellm.secret_managers.main import str_to_bool
|
||||
|
||||
_use_redis_transaction_buffer: bool | str | None = general_settings.get("use_redis_transaction_buffer", False)
|
||||
|
|
@ -7287,6 +7286,8 @@ class ProxyStartupEvent:
|
|||
if not _use_redis_transaction_buffer:
|
||||
return None
|
||||
|
||||
from litellm._redis import _redis_kwargs_from_environment
|
||||
|
||||
redis_env_kwargs = _redis_kwargs_from_environment()
|
||||
if "host" not in redis_env_kwargs and "url" not in redis_env_kwargs:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -360,6 +360,20 @@ def test_get_transaction_buffer_redis_cache_none_without_host_or_url():
|
|||
assert result is None
|
||||
|
||||
|
||||
def test_get_transaction_buffer_redis_cache_does_not_import_redis_when_disabled():
|
||||
"""
|
||||
When the buffer is disabled, litellm._redis (which imports redis.asyncio) must not be
|
||||
imported, so the proxy starts even in deployments without the redis package installed.
|
||||
|
||||
Regression test for https://github.com/BerriAI/litellm/issues/32592
|
||||
"""
|
||||
with patch.dict(sys.modules, {"litellm._redis": None}):
|
||||
result = ProxyStartupEvent._get_transaction_buffer_redis_cache(
|
||||
general_settings={},
|
||||
)
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_get_transaction_buffer_redis_cache_parses_string_flag(monkeypatch):
|
||||
"""
|
||||
use_redis_transaction_buffer accepts a string value (e.g. from env/YAML); "true"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue