From 05de6d0f4835362a6bd3a757cd8ee98e9b34724f Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Tue, 24 Oct 2023 19:10:07 +0300 Subject: [PATCH] [BUG]: Removed mutable default values in Ephemeral, Persistent and Http clients (#1270) ## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - Removed mutable default settings and headers, as this seems ## Test plan *How are these changes tested?* - [x] Tests pass locally with `pytest` for python ## Documentation Changes N/A This issue partly resolves - #1209 (for multiple local persistent clients with different persist paths) --- chromadb/__init__.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/chromadb/__init__.py b/chromadb/__init__.py index eeb5eaf5899..f56bae8973a 100644 --- a/chromadb/__init__.py +++ b/chromadb/__init__.py @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, Optional import logging from chromadb.api.client import Client as ClientCreator from chromadb.api.client import AdminClient as AdminClientCreator @@ -95,7 +95,7 @@ def get_settings() -> Settings: def EphemeralClient( - settings: Settings = Settings(), + settings: Optional[Settings] = None, tenant: str = DEFAULT_TENANT, database: str = DEFAULT_DATABASE, ) -> ClientAPI: @@ -107,6 +107,8 @@ def EphemeralClient( tenant: The tenant to use for this client. Defaults to the default tenant. database: The database to use for this client. Defaults to the default database. """ + if settings is None: + settings = Settings() settings.is_persistent = False return ClientCreator(settings=settings, tenant=tenant, database=database) @@ -114,7 +116,7 @@ def EphemeralClient( def PersistentClient( path: str = "./chroma", - settings: Settings = Settings(), + settings: Optional[Settings] = None, tenant: str = DEFAULT_TENANT, database: str = DEFAULT_DATABASE, ) -> ClientAPI: @@ -127,6 +129,8 @@ def PersistentClient( tenant: The tenant to use for this client. Defaults to the default tenant. database: The database to use for this client. Defaults to the default database. """ + if settings is None: + settings = Settings() settings.persist_directory = path settings.is_persistent = True @@ -137,8 +141,8 @@ def HttpClient( host: str = "localhost", port: str = "8000", ssl: bool = False, - headers: Dict[str, str] = {}, - settings: Settings = Settings(), + headers: Optional[Dict[str, str]] = None, + settings: Optional[Settings] = None, tenant: str = DEFAULT_TENANT, database: str = DEFAULT_DATABASE, ) -> ClientAPI: @@ -156,6 +160,11 @@ def HttpClient( database: The database to use for this client. Defaults to the default database. """ + if headers is None: + headers = {} + if settings is None: + settings = Settings() + settings.chroma_api_impl = "chromadb.api.fastapi.FastAPI" settings.chroma_server_host = host settings.chroma_server_http_port = port