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 same stale-overwrite bug in update_useful_links
yuneng-jiangdb0819ad26f6
diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.pyindex cd7e3d15402..0fbe2f8ab18 100644--- a/litellm/proxy/management_endpoints/model_management_endpoints.py+++ b/litellm/proxy/management_endpoints/model_management_endpoints.py@@ -1256,9 +1256,8 @@ async def update_useful_links(},)- litellm.public_model_groups_links = request.useful_links-- # Load existing config+ # Load existing config first (this may overwrite in-memory litellm settings+ # from DB values via _update_config_from_db), so set the in-memory value AFTERconfig = await proxy_config.get_config()# Update config with new settings@@ -1270,6 +1269,10 @@ async def update_useful_links(# Save the updated configawait proxy_config.save_config(new_config=config)+ # Set in-memory value AFTER get_config() and save_config() to avoid+ # get_config() overwriting with stale DB value+ litellm.public_model_groups_links = request.useful_links+verbose_proxy_logger.debug(f"Updated useful links to: {request.useful_links} by user: {user_api_key_dict.user_id}")diff --git a/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.pyindex d669c878d04..f3c89003105 100644--- a/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py@@ -510,6 +510,53 @@ class TestUpdatePublicModelGroups:finally:litellm.public_model_groups = original_value+ @pytest.mark.asyncio+ async def test_useful_links_set_after_get_config(self):+ """+ Regression test: same stale-overwrite bug as public_model_groups applies+ to update_useful_links / public_model_groups_links.+ """+ import litellm+ from litellm.proxy.management_endpoints.model_management_endpoints import (+ update_useful_links,+ )+ from litellm.types.proxy.management_endpoints.model_management_endpoints import (+ UpdateUsefulLinksRequest,+ )++ old_links = {"Old Doc": "https://old.example.com"}+ new_links = {"New Doc": "https://new.example.com", "API Ref": "https://api.example.com"}++ async def mock_get_config(*args, **kwargs):+ litellm.public_model_groups_links = old_links+ return {"litellm_settings": {"public_model_groups_links": old_links}}++ mock_proxy_config = MagicMock()+ mock_proxy_config.get_config = mock_get_config+ mock_proxy_config.save_config = AsyncMock()++ admin_user = UserAPIKeyAuth(+ user_id="admin", user_role=LitellmUserRoles.PROXY_ADMIN+ )++ request = UpdateUsefulLinksRequest(useful_links=new_links)++ original_value = getattr(litellm, "public_model_groups_links", None)+ try:+ with patch(+ "litellm.proxy.proxy_server.proxy_config",+ mock_proxy_config,+ ):+ result = await update_useful_links(+ request=request,+ user_api_key_dict=admin_user,+ )++ assert litellm.public_model_groups_links == new_links+ assert result["useful_links"] == new_links+ finally:+ litellm.public_model_groups_links = original_value+class TestTeamModelUpdate:"""Test team model update handles team_id consistently with model creation"""