The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Use passed general_settings parameter instead of global import
yuneng-jiang9d9a59190c47
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex d0d132c313d..d8304cabd56 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -5638,14 +5638,15 @@ class ProxyStartupEvent:- The pod lock manager cannot acquire locks for DB commits- No fallback to direct DB writes occurs"""- from litellm.proxy.db.db_transaction_queue.redis_update_buffer import (- RedisUpdateBuffer,+ from litellm.secret_managers.main import str_to_bool++ _use_redis_transaction_buffer: Optional[Union[bool, str]] = (+ general_settings.get("use_redis_transaction_buffer", False))+ if isinstance(_use_redis_transaction_buffer, str):+ _use_redis_transaction_buffer = str_to_bool(_use_redis_transaction_buffer)- if (- RedisUpdateBuffer._should_commit_spend_updates_to_redis()- and redis_usage_cache is None- ):+ if _use_redis_transaction_buffer and redis_usage_cache is None:raise ValueError("`use_redis_transaction_buffer` is enabled in general_settings, ""but no Redis cache is configured. Spend tracking will silently "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.pyindex a77b8d49b6a..78e07c29677 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@@ -1,7 +1,7 @@import jsonimport osimport sys-from unittest.mock import AsyncMock, MagicMock, patch+from unittest.mock import AsyncMock, MagicMockimport pytest@@ -200,16 +200,11 @@ def test_validate_redis_transaction_buffer_raises_without_redis():When use_redis_transaction_buffer=true but no Redis cache is configured,the proxy should refuse to start with a clear error message."""- general_settings = {"use_redis_transaction_buffer": True}-- with patch(- "litellm.proxy.proxy_server.general_settings", general_settings- ):- with pytest.raises(ValueError, match="use_redis_transaction_buffer"):- ProxyStartupEvent._validate_redis_transaction_buffer_config(- general_settings=general_settings,- redis_usage_cache=None,- )+ with pytest.raises(ValueError, match="use_redis_transaction_buffer"):+ ProxyStartupEvent._validate_redis_transaction_buffer_config(+ general_settings={"use_redis_transaction_buffer": True},+ redis_usage_cache=None,+ )def test_validate_redis_transaction_buffer_passes_with_redis():@@ -217,17 +212,11 @@ def test_validate_redis_transaction_buffer_passes_with_redis():When use_redis_transaction_buffer=true and Redis cache is configured,validation should pass without error."""- general_settings = {"use_redis_transaction_buffer": True}- mock_redis_cache = MagicMock()-- with patch(- "litellm.proxy.proxy_server.general_settings", general_settings- ):- # Should not raise- ProxyStartupEvent._validate_redis_transaction_buffer_config(- general_settings=general_settings,- redis_usage_cache=mock_redis_cache,- )+ # Should not raise+ ProxyStartupEvent._validate_redis_transaction_buffer_config(+ general_settings={"use_redis_transaction_buffer": True},+ redis_usage_cache=MagicMock(),+ )def test_validate_redis_transaction_buffer_passes_when_disabled():@@ -235,11 +224,8 @@ def test_validate_redis_transaction_buffer_passes_when_disabled():When use_redis_transaction_buffer is not set or false,validation should pass regardless of Redis configuration."""- with patch(- "litellm.proxy.proxy_server.general_settings", {}- ):- # Should not raise even without Redis- ProxyStartupEvent._validate_redis_transaction_buffer_config(- general_settings={},- redis_usage_cache=None,- )+ # Should not raise even without Redis+ ProxyStartupEvent._validate_redis_transaction_buffer_config(+ general_settings={},+ redis_usage_cache=None,+ )