fix: VectorStore registries use None default to avoid mutable default arguments

Fixes #38874 - VectorStoreIndexRegistry and VectorStoreRegistry use mutable
default list arguments ([]), causing shared state between instances.

Changed both classes to use None as the default and instantiate a new list
per instance, matching the convention used throughout the codebase.
This commit is contained in:
shuwen.wu 2026-09-02 17:59:36 +08:00
parent 31ca4ddf32
commit 32296d54c2

View file

@ -6,6 +6,7 @@ from typing import (
TYPE_CHECKING,
Any, # noqa: TID251 # untyped non_default_params dict is the only source of the unknown key type
Final,
Optional,
cast, # noqa: TID251 # untyped non_default_params dict is the only source of the unknown key type
get_args,
)
@ -32,8 +33,13 @@ else:
class VectorStoreIndexRegistry:
def __init__(self, vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = []):
self.vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = vector_store_indexes
def __init__(
self,
vector_store_indexes: Optional[list[LiteLLM_ManagedVectorStoreIndex]] = None,
):
self.vector_store_indexes: list[LiteLLM_ManagedVectorStoreIndex] = (
vector_store_indexes if vector_store_indexes is not None else []
)
def get_vector_store_indexes(self) -> list[LiteLLM_ManagedVectorStoreIndex]:
"""
@ -101,8 +107,13 @@ class VectorStoreIndexRegistry:
class VectorStoreRegistry:
def __init__(self, vector_stores: list[LiteLLM_ManagedVectorStore] = []):
self.vector_stores: list[LiteLLM_ManagedVectorStore] = vector_stores
def __init__(
self,
vector_stores: Optional[list[LiteLLM_ManagedVectorStore]] = None,
):
self.vector_stores: list[LiteLLM_ManagedVectorStore] = (
vector_stores if vector_stores is not None else []
)
self.vector_store_ids_to_vector_store_map: dict[str, LiteLLM_ManagedVectorStore] = {}
def _extract_tool_params(self, tool: dict) -> VectorStoreToolParams: