Skip to content

Commit 7a3b397

Browse files
authored
[BUG] explicitly allow extra params (#6534)
pydantic's default behavior should be to ignore extra params. In practice, we see it error if extra params are provided https://docs.pydantic.dev/latest/concepts/models/#extra-data This explicitly sets the "extra" param
1 parent 07f9750 commit 7a3b397

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

chromadb/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def __getitem__(self, key: str) -> Any:
317317
raise ValueError(LEGACY_ERROR)
318318
return val
319319

320-
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
320+
model_config = {"env_file": ".env", "env_file_encoding": "utf-8", "extra": "ignore"}
321321

322322

323323
T = TypeVar("T", bound="Component")

chromadb/test/test_config.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from chromadb.config import Component, System, Settings
22
from overrides import overrides
33
from threading import local
4+
from unittest.mock import patch
5+
import pytest
6+
import os
47
import random
58

69
data = local() # use thread local just in case tests ever run in parallel
@@ -207,3 +210,25 @@ def test_http_client_setting_overrides() -> None:
207210
assert settings.chroma_http_keepalive_secs == 5.5
208211
assert settings.chroma_http_max_connections == 123
209212
assert settings.chroma_http_max_keepalive_connections == 17
213+
214+
215+
@patch.dict(os.environ, {"CHROMA_API_IMPL": "my_api_impl"}, clear=True)
216+
def test_uses_env() -> None:
217+
settings = Settings()
218+
assert settings.chroma_api_impl == "my_api_impl"
219+
220+
221+
@patch.dict(os.environ, {"MY_ENV_VAR": "my_env_var"}, clear=True)
222+
def test_ignores_extra_env_vars() -> None:
223+
settings = Settings()
224+
with pytest.raises(AttributeError):
225+
_ = settings.my_env_var
226+
227+
228+
def test_local_ignores_extra_settings_param() -> None:
229+
settings = Settings(extra_param="asdsdsds", tenant_id="test")
230+
# does not error if the extra param is present in the settings object
231+
assert settings.tenant_id == "test"
232+
# but it should error if the extra param is accessed
233+
with pytest.raises(AttributeError):
234+
_ = settings.extra_param

0 commit comments

Comments
 (0)