[BUG]: Ignore extra env vars in Settings to prevent ValidationError#6535
[BUG]: Ignore extra env vars in Settings to prevent ValidationError#6535basnijholt wants to merge 3 commits intochroma-core:mainfrom
Conversation
`pydantic_settings.BaseSettings` defaults to `extra="forbid"`, which means any environment variable or `.env` key that doesn't match a `Settings` field raises a `ValidationError` at import time. This is a follow-up to chroma-core#6356 which switched from pydantic v1 `BaseSettings` to pydantic-settings v2. The old v1 `BaseSettings` silently ignored unrecognized env vars, but v2 rejects them by default. Adding `"extra": "ignore"` restores the previous tolerance so users with unrelated env vars (e.g. `OPENAI_API_KEY`, `GEMINI_API_KEY`) in their environment or `.env` file can import chromadb without errors.
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
|
It also adds regression tests to confirm extra environment variables and initialization kwargs are ignored and not exposed as attributes. Possible Issues• Ignoring extras could mask typos in environment variable names, which may delay detection of misconfiguration. This summary was automatically generated by @propel-code-bot |
|
Yeah, I have a hangup for your test because you're using os.chdir and writing to the filesystem. There's an easier way to test this using pytest's tools. I wouldn't mind if you just copy the tests from this PR, and we can merge this PR |
|
@kylediaz I did that! 😄 |
|
We added multi-cloud support for multi-node Chroma, so our CI is broken for external contributors. I need to get a repo admin to bypass the merge requirements. Sorry about this! |
Follow-up to #6356 — that PR switched
Settingsfrom pydantic v1BaseSettingstopydantic_settings.BaseSettings(v2), but didn't setextra="ignore".pydantic_settings.BaseSettingsv2 defaults toextra="forbid", so any environment variable or.envkey that doesn't match aSettingsfield (e.g.OPENAI_API_KEY,GEMINI_API_KEY) raises aValidationErrorat import time:The old pydantic v1
BaseSettingssilently ignored unrecognized env vars. Adding"extra": "ignore"tomodel_configrestores that behavior.