Migrate ChromaDB from Pydantic v1 to v2 for Python 3.14.0 compatibility#5842
Migrate ChromaDB from Pydantic v1 to v2 for Python 3.14.0 compatibility#5842mpurland wants to merge 1 commit intochroma-core:mainfrom
Conversation
Complete migration to Pydantic v2, removing all v1 compatibility layers and updating dependencies for Python 3.14.0 support. Dependencies: - Update pydantic from >=1.9 to >=2.0,<3.0 in main package - Add pydantic-settings>=2.0,<3.0 (BaseSettings moved to separate package) - Update client pydantic to >=2.12.4 - Remove graphlib_backport (built-in since Python 3.9) chromadb/config.py: - Remove Pydantic v1/v2 compatibility detection layer - Import BaseSettings from pydantic_settings instead of pydantic - Convert @validator to @field_validator with mode="before" and @classmethod - Convert inner class Config to model_config dict - Add type annotations to chroma_coordinator_host, chroma_logservice_host, and chroma_logservice_port (Pydantic v2 requirement) - Add extra="ignore" to model_config to handle extra environment variables (Pydantic v2 forbids extra fields by default, unlike v1) chromadb/server/fastapi/__init__.py: - Remove validate_model() compatibility function - Replace all validate_model(Model, data) calls with Model.model_validate(data) (20 occurrences across v1 and v2 API endpoints) chromadb/types.py: - Remove get_model_fields() compatibility method - Replace self.get_model_fields() with type(self).model_fields (4 occurrences in __getitem__, __setitem__, __eq__) rust/python_bindings/Cargo.toml: - Update version from "0.1.0" to "1.3.3" to match git tags All compatibility shims removed for a cleaner Pydantic v2-only codebase. Tested with Python 3.14.0.
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
|
Fully migrate ChromaDB to Pydantic v2 and enable Python 3.14 support This PR removes the dual-support layer for Pydantic v1 and upgrades the entire code-base, build tooling and dependencies to Pydantic v2. By doing so ChromaDB now compiles and runs on the upcoming Python 3.14 release and aligns with the wider ecosystem shift toward the v2 API surface. Most changes touch configuration models, validators, and helper utilities that previously straddled both Pydantic versions, while core database behaviour remains untouched. All v1-specific shims (e.g. custom validators, Config inner classes, helper wrappers) are dropped in favour of the v2 Key Changes• Bumps core dependency to pydantic>=2.0,<3.0 and introduces pydantic-settings>=2.0,<3.0 Affected Areas• chromadb/config.py This summary was automatically generated by @propel-code-bot |
|
This is important to be able to run chroma on Python 3.14. |
…6356) Fixes #5996 — chromadb crashes on import with Python 3.14 because `pydantic.v1` compat layer breaks on 3.14. The rest of the codebase already uses pydantic v2 APIs, so this just drops the v1 shim in `config.py`: - Use `pydantic_settings.BaseSettings` + `pydantic.field_validator` directly - Add missing type annotations on 3 fields (`chroma_coordinator_host`, `chroma_logservice_host`, `chroma_logservice_port`) — required by pydantic v2 - `class Config` → `model_config` dict - Bump dep to `pydantic >= 2.0`, add `pydantic-settings >= 2.0` There's a larger PR in #5842 that also cleans up `fastapi/__init__.py` and `types.py`, but those files already work fine — this is just the minimum to unbreak 3.14. Tested on Python 3.14.1: import works, `test_config.py` passes, `PersistentClient` round-trips documents. --------- Co-authored-by: Kyle Diaz <[email protected]>
|
We merged another PR that fixes this. It should be in the latest release. Thanks for bringing this to our attention! |
Description of changes
Complete migration to Pydantic v2, removing all v1 compatibility layers
and updating dependencies for Python 3.14.0 support.
Dependencies:
chromadb/config.py:
chromadb/server/fastapi/init.py:
chromadb/types.py:
rust/python_bindings/Cargo.toml:
All compatibility shims removed for a cleaner Pydantic v2-only codebase.
Tested with Python 3.14.0.
Test plan
Setup venv as necessary. Installs should be in the intended venv. e.g. source /path/to/venv/bin/activatge
Clone onnxruntime (1.23.2) and install
Install works after manually cloning onnxruntime (latest 1.23.2), building from source, and installing.
On Mac:
./build.sh --config Release --build_wheel --parallel --skip_tests --use_coremlProduces this artifact in
pip install onnxruntime-1.24.0-cp314-cp314-macosx_15_0_arm64.whlInstall via:
pip install -e .Latest chromadb should be working in Python 3.14.0 with your project.
I hope this helps other people trying to get recent ChromaDB working with Python 3.14.0.
pytestfor python,yarn testfor js,cargo testfor rustMigration plan
Pydantic V1 to Pydantic V2. This allows projects to use Pydantic V2. This is a breaking change.
Observability plan
This is a breaking change.
Documentation Changes
Yes, since dependencies were updated. Pydantic V2.