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(vector_store): tighten registry-mutation comment and dedupe test helpers

user38511675b16f
diff --git a/litellm/proxy/vector_store_endpoints/endpoints.py b/litellm/proxy/vector_store_endpoints/endpoints.py
index 0f9753a303a..ccf15c206b0 100644
--- a/litellm/proxy/vector_store_endpoints/endpoints.py
+++ b/litellm/proxy/vector_store_endpoints/endpoints.py
@@ -8,6 +8,9 @@ from litellm.proxy._types import CommonProxyErrors, UserAPIKeyAuth
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
from litellm.proxy.utils import jsonify_object
+from litellm.proxy.vector_store_endpoints.management_endpoints import (
+ _resolve_embedding_config,
+)
from litellm.proxy.vector_store_endpoints.utils import (
assert_user_can_access_vector_store,
get_litellm_managed_vector_store,
@@ -66,14 +69,16 @@ async def _update_request_data_with_litellm_managed_vector_store_registry(
embedding_model = litellm_params.get("litellm_embedding_model")
if embedding_model and not litellm_params.get("litellm_embedding_config"):
from litellm.proxy.proxy_server import prisma_client
- from litellm.proxy.vector_store_endpoints.management_endpoints import (
- _resolve_embedding_config,
- )
resolved_config = await _resolve_embedding_config(
embedding_model=embedding_model, prisma_client=prisma_client
)
if resolved_config:
+ # Build a fresh dict via spread instead of mutating
+ # ``litellm_params`` in place — the registry hands back
+ # a reference to its cached object, so an in-place
+ # update would persist the resolved cleartext into the
+ # in-memory cache for the lifetime of the process.
litellm_params = {
**litellm_params,
"litellm_embedding_config": resolved_config,
diff --git a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
index 7f5557f41ed..8fc7bc4e268 100644
--- a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
+++ b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
@@ -36,6 +36,20 @@ from litellm.proxy.vector_store_endpoints.utils import (
from litellm.types.utils import LlmProviders
+def _serialize_litellm_params(litellm_params):
+ """Serialize ``litellm_params`` to a string for substring assertions.
+
+ The redact helper preserves the persisted shape — string in, string
+ out; dict in, dict out — so callers that just want to assert "this
+ secret never appears" need a single text representation either way.
+ """
+ import json
+
+ if isinstance(litellm_params, str):
+ return litellm_params
+ return json.dumps(litellm_params or {})
+
+
@pytest.mark.asyncio
async def test_router_avector_store_search_passes_correct_args():
"""
@@ -202,7 +216,7 @@ async def test_update_request_data_resolves_embedding_config_at_use_time():
with (
patch.object(litellm, "vector_store_registry", mock_registry),
patch(
- "litellm.proxy.vector_store_endpoints.management_endpoints._resolve_embedding_config",
+ "litellm.proxy.vector_store_endpoints.endpoints._resolve_embedding_config",
new=AsyncMock(return_value=resolved),
),
):
@@ -240,14 +254,12 @@ async def test_update_request_data_passes_through_legacy_embedding_config():
mock_vector_store
)
- resolve_mock = AsyncMock(
- return_value={"api_key": "should-not-be-used", "api_base": "wrong"}
- )
+ resolve_mock = AsyncMock()
with (
patch.object(litellm, "vector_store_registry", mock_registry),
patch(
- "litellm.proxy.vector_store_endpoints.management_endpoints._resolve_embedding_config",
+ "litellm.proxy.vector_store_endpoints.endpoints._resolve_embedding_config",
new=resolve_mock,
),
):
@@ -1523,14 +1535,8 @@ async def test_new_vector_store_auto_resolves_embedding_config():
# cleartext or pre-existing rows that were created by an earlier
# proxy version.
response_vs = result["vector_store"]
- response_params = response_vs.get("litellm_params")
- # The redact helper preserves the persisted shape (string or dict);
- # serialise to text either way and assert the cleartext credential
- # never appears.
- assert "resolved-api-key" not in (
- response_params
- if isinstance(response_params, str)
- else json.dumps(response_params or {})
+ assert "resolved-api-key" not in _serialize_litellm_params(
+ response_vs.get("litellm_params")
)
@@ -1797,11 +1803,8 @@ async def test_new_vector_store_auto_resolves_from_router():
assert litellm_params_dict["litellm_embedding_model"] == "config-embedding-model"
response_vs = result["vector_store"]
- response_params = response_vs.get("litellm_params")
- assert "router-resolved-api-key" not in (
- response_params
- if isinstance(response_params, str)
- else json.dumps(response_params or {})
+ assert "router-resolved-api-key" not in _serialize_litellm_params(
+ response_vs.get("litellm_params")
)