Skip to content

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]

fix(proxy): stop empty DB router_settings lists from clobbering yaml fallbacks

mateo-berri6d1b295daeab
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index e55b254ab8e..196c9b017ce 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -6268,7 +6268,10 @@ class ProxyConfig:
):
from litellm.utils import _update_dictionary
- combined_router_settings = _update_dictionary(config_router_settings, db_router_settings.param_value)
+ 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)
+ }
+ combined_router_settings = _update_dictionary(config_router_settings, db_overlay_without_empty_lists)
elif config_router_settings is not None and isinstance(config_router_settings, dict):
combined_router_settings = config_router_settings
elif 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.py
index afc42e8db45..0686df39eda 100644
--- a/tests/test_litellm/proxy/test_proxy_server.py
+++ b/tests/test_litellm/proxy/test_proxy_server.py
@@ -4741,6 +4741,55 @@ async def test_add_router_settings_from_db_config_merge_logic():
assert combined_settings["nested_config"] == expected_nested
+async def test_add_router_settings_from_db_config_empty_db_lists_do_not_clobber_config_fallbacks():
+ """
+ Regression test for DB router_settings rows carrying explicit empty lists
+ (e.g. {"fallbacks": []} written by the dashboard's delete-last-fallback flow):
+ empty lists are "no value" and must not clobber config.yaml fallbacks,
+ matching _deep_merge_dicts semantics. Non-empty DB lists still win.
+ """
+ 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": {
+ "fallbacks": [{"gpt-oss-120b": ["granite-4-h-small"]}],
+ "context_window_fallbacks": [{"gpt-oss-120b": ["granite-4-h-small"]}],
+ "content_policy_fallbacks": [{"gpt-oss-120b": ["granite-4-h-small"]}],
+ }
+ }
+
+ mock_db_config = MagicMock()
+ mock_db_config.param_value = {
+ "fallbacks": [],
+ "context_window_fallbacks": [],
+ "content_policy_fallbacks": [{"gpt-oss-120b": ["other-model"]}],
+ "model_group_alias": {},
+ "num_retries": 3,
+ }
+
+ 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"] == [{"gpt-oss-120b": ["granite-4-h-small"]}]
+ assert combined_settings["context_window_fallbacks"] == [{"gpt-oss-120b": ["granite-4-h-small"]}]
+ assert combined_settings["content_policy_fallbacks"] == [{"gpt-oss-120b": ["other-model"]}]
+ assert combined_settings["num_retries"] == 3
+
+
@pytest.mark.asyncio
async def test_add_router_settings_from_db_config_edge_cases():
"""