From cd7c8e4041abb6ba7e578aa023a521296d177ecd Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 07:06:54 +0000 Subject: [PATCH] fix(proxy): don't import redis.asyncio on startup when transaction buffer is disabled --- litellm/proxy/proxy_server.py | 3 ++- .../test_redis_update_buffer.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 13e2d4f1252..040ef06d088 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -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 diff --git a/tests/test_litellm/proxy/db/db_transaction_queue/test_redis_update_buffer.py b/tests/test_litellm/proxy/db/db_transaction_queue/test_redis_update_buffer.py index 33372e7794a..6e8fe5f7887 100644 --- a/tests/test_litellm/proxy/db/db_transaction_queue/test_redis_update_buffer.py +++ b/tests/test_litellm/proxy/db/db_transaction_queue/test_redis_update_buffer.py @@ -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"