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
fix(proxy): apply empty DB router_settings lists only where yaml sets no value
mateo-berri3b9f6ee2aaf5
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 196c9b017ce..9a3905da950 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -6268,10 +6268,14 @@ class ProxyConfig:):from litellm.utils import _update_dictionary- db_overlay_without_empty_lists: Final = {- k: v for k, v in db_router_settings.param_value.items() if not (isinstance(v, list) and len(v) == 0)+ db_overlay_deferring_empty_lists_to_config: Final = {+ k: v+ for k, v in db_router_settings.param_value.items()+ if not (k in config_router_settings and isinstance(v, list) and len(v) == 0)}- combined_router_settings = _update_dictionary(config_router_settings, db_overlay_without_empty_lists)+ combined_router_settings = _update_dictionary(+ config_router_settings, db_overlay_deferring_empty_lists_to_config+ )elif config_router_settings is not None and isinstance(config_router_settings, dict):combined_router_settings = config_router_settingselif db_router_settings is not None and isinstance(db_router_settings.param_value, dict):diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.pyindex 0686df39eda..fc9d0a96163 100644--- a/tests/test_litellm/proxy/test_proxy_server.py+++ b/tests/test_litellm/proxy/test_proxy_server.py@@ -4790,6 +4790,41 @@ async def test_add_router_settings_from_db_config_empty_db_lists_do_not_clobber_assert combined_settings["num_retries"] == 3+async def test_add_router_settings_from_db_config_empty_db_list_still_clears_unconfigured_key():+ """+ An empty DB list only yields to config.yaml where the yaml configures that key.+ When the yaml router_settings has no fallbacks, a DB {"fallbacks": []} (the+ dashboard's delete-last-fallback write) must still reach the router so the+ running pods drop the deleted fallback without a restart.+ """+ from unittest.mock import AsyncMock, MagicMock++ from litellm.proxy.proxy_server import ProxyConfig++ proxy_config = ProxyConfig()+ mock_router = MagicMock()+ mock_router.update_settings = MagicMock()++ config_data = {"router_settings": {"num_retries": 1}}++ mock_db_config = MagicMock()+ mock_db_config.param_value = {"fallbacks": [], "model_group_alias": {}}++ mock_prisma_client = MagicMock()+ mock_prisma_client.db.litellm_config.find_first = AsyncMock(return_value=mock_db_config)++ await proxy_config._add_router_settings_from_db_config(+ config_data=config_data,+ llm_router=mock_router,+ prisma_client=mock_prisma_client,+ )++ combined_settings = mock_router.update_settings.call_args.kwargs+ assert combined_settings["fallbacks"] == []+ assert combined_settings["num_retries"] == 1++@pytest.mark.asyncioasync def test_add_router_settings_from_db_config_edge_cases():"""@@ -11353,9 +11388,7 @@ class TestRouterModelNameOnStreamingChunks:with patch.object(ProxyLogging, "_fire_deferred_stream_logging"):return [data- async for data in async_data_generator(- mock_response, MagicMock(spec=UserAPIKeyAuth), request_data- )+ async for data in async_data_generator(mock_response, MagicMock(spec=UserAPIKeyAuth), request_data)]@staticmethod