Skip to content

[BUG]: Drop pydantic v1 compatibility layer for Python 3.14 support#6356

Merged
HammadB merged 3 commits intochroma-core:mainfrom
basnijholt:fix-python-3.14-pydantic-v2
Mar 2, 2026
Merged

[BUG]: Drop pydantic v1 compatibility layer for Python 3.14 support#6356
HammadB merged 3 commits intochroma-core:mainfrom
basnijholt:fix-python-3.14-pydantic-v2

Conversation

@basnijholt
Copy link
Copy Markdown
Contributor

@basnijholt basnijholt commented Feb 6, 2026

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 Configmodel_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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 6, 2026

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@basnijholt basnijholt force-pushed the fix-python-3.14-pydantic-v2 branch from 5d8e026 to 7c2b8ab Compare February 6, 2026 03:52
basnijholt added a commit to basnijholt/agent-cli that referenced this pull request Feb 6, 2026
Patch pydantic at runtime so chromadb's broken pydantic v1 usage works
on 3.14. Remove once chromadb ships a fix (chroma-core/chroma#6356).
basnijholt added a commit to basnijholt/agent-cli that referenced this pull request Feb 6, 2026
Patch pydantic at runtime so chromadb's broken pydantic v1 usage works
on 3.14. Remove once chromadb ships a fix (chroma-core/chroma#6356).
@cdeil
Copy link
Copy Markdown

cdeil commented Feb 6, 2026

@basnijholt - thank you!

Maintainers: Would be great if you could merge this important fix! :-)

The v2 for Pydantic and also Pydantic-settings was released in June 2023, hopefully an acceptable version bump for you.

@basnijholt
Copy link
Copy Markdown
Contributor Author

@HammadB, just to make it obvious–currently at least 1000 downstream dependencies of ChromaDB cannot support Python 3.14 because this simple problem.

In my own library that uses ChromaDB, I have to jump through insane runtime monkeypatching to get it to work (basnijholt/agent-cli@6f868f5).

I am confident that almost all developers would value supporting new Python versions over backward compatibility with pydantic v1.

@basnijholt
Copy link
Copy Markdown
Contributor Author

9 out of 10 major chromadb dependents already require pydantic v2 (directly or transitively), so the v1 compat layer serves essentially no one:

Package Requires pydantic v2? Via Constraint
langchain-chroma Yes langchain-core pydantic<3.0.0,>=2.7.4
llama-index-vector-stores-chroma Yes llama-index-core pydantic>=2.8.0
crewai Yes instructor pydantic<3.0.0,>=2.8.0
embedchain Yes langchain pydantic<3.0.0,>=2.7.4
semantic-kernel Yes direct pydantic!=2.10.0,!=2.10.1,!=2.10.2,!=2.10.3,<2.12,>=2.0
mem0ai Yes direct pydantic>=2.7.3
superagi Yes langchain pydantic<3.0.0,>=2.7.4
llmware Yes transformers pydantic>=2
langflow Yes assemblyai pydantic>=2.0
chromadb-client No

The only holdout is chromadb-client — chromadb's own package.

Reproduce with this script
"""Check whether major chromadb dependents already require pydantic v2."""
import json, re, urllib.request

def get_requires_dist(pkg):
    try:
        url = f"https://pypi.org/pypi/{pkg}/json"
        req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
        with urllib.request.urlopen(req, timeout=10) as resp:
            data = json.loads(resp.read())
        return data.get("info", {}).get("requires_dist") or []
    except Exception:
        return []

def find_pydantic_v2_req(pkg, depth=0, visited=None):
    if visited is None:
        visited = set()
    if pkg in visited or depth > 2:
        return None
    visited.add(pkg)
    for dep in get_requires_dist(pkg):
        dep_clean = re.split(r"\s*;", dep)[0].strip()
        dep_name = re.split(r"[\s>=<\[!]", dep_clean)[0].lower()
        if dep_name == "pydantic" and re.search(r">=\s*2", dep):
            return (pkg if depth > 0 else "direct", dep_clean)
        if depth < 1 and dep_name not in visited:
            result = find_pydantic_v2_req(dep_name, depth + 1, visited)
            if result:
                return result
    return None

for pkg in [
    "langchain-chroma", "llama-index-vector-stores-chroma",
    "crewai", "embedchain", "semantic-kernel", "mem0ai",
    "superagi", "llmware", "langflow", "chromadb-client",
]:
    result = find_pydantic_v2_req(pkg)
    if result:
        via, constraint = result
        print(f"{pkg}: requires pydantic v2 (via {via}) — {constraint}")
    else:
        print(f"{pkg}: does NOT require pydantic v2")

Gictfuchs pushed a commit to Gictfuchs/openclaw that referenced this pull request Feb 11, 2026
VectorStore now operates as a silent no-op when ChromaDB cannot be
imported (pydantic-v1 incompatibility on Python 3.14).  SQLite memory
and all other features continue working; only semantic vector search is
disabled until ChromaDB ships a fix (PR chroma-core/chroma#6356).

Simplified test skip logic to import HAS_CHROMADB from the module.
Memory-tools tests no longer skip since they only use mocks.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@MarcSkovMadsen
Copy link
Copy Markdown

+1

1 similar comment
@crydafan
Copy link
Copy Markdown

+1

bhive01 pushed a commit to bmconklin/DeeSim that referenced this pull request Feb 22, 2026
ChromaDB depends on pydantic v1 which raises a ConfigError on
Python 3.14 due to removed internal CPython APIs.  This breaks the
MCP server on import (state_manager.py line 13).

Changes:
- Wrap chromadb import in try/except; export HAS_CHROMADB flag
- Guard get_chroma_client, get_chat_collection,
  get_session_summary_collection with early None returns
- search_archived_summaries returns a helpful no-op message
- save_chat_snapshot skips ChromaDB sync when unavailable
- Log a warning at startup when vector search is disabled
- Move chromadb from required to optional dependency (pip install
  deesim[vector])

All non-vector functionality (file-based chat history, SQLite
inventory/quests, dice, rules lookup, etc.) continues to work.

Ref: chroma-core/chroma#6356

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@kylediaz kylediaz force-pushed the fix-python-3.14-pydantic-v2 branch from 7c2b8ab to bfb26eb Compare February 26, 2026 19:38
@propel-code-bot
Copy link
Copy Markdown
Contributor

propel-code-bot bot commented Feb 26, 2026

This also updates dependency constraints across server and client packaging to require pydantic v2 and pydantic-settings.

Possible Issues

• Any downstream code relying on pydantic v1 behavior may need updates after the version bump.
• Verify environment-based settings still load correctly with pydantic-settings.

This summary was automatically generated by @propel-code-bot

propel-code-bot[bot]

This comment was marked as outdated.

propel-code-bot[bot]

This comment was marked as outdated.

@kylediaz kylediaz force-pushed the fix-python-3.14-pydantic-v2 branch from 671a28a to b80822d Compare February 26, 2026 21:03
propel-code-bot[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review found no issues and the changes align with intended updates.

Status: No Issues Found | Risk: Low

Review Details

📁 14 files reviewed | 💬 0 comments

Instruction Files
└── docs/
    └── mintlify/
        ├── AGENTS.md
        └── CLAUDE.md

@basnijholt
Copy link
Copy Markdown
Contributor Author

@kylediaz I pushed a follow-up fix for the remaining Python 3.14 test failure in this PR (808c452).

I fixed chromadb/test/property/test_cross_version_persist.py so it skips historical chromadb versions that cannot import on Python 3.14 due to pydantic.v1 incompatibility (chroma_server_nofile ConfigError), while still running cross-version coverage for supported versions.

I verified locally with:

  • pytest chromadb/test/property/test_cross_version_persist.py
  • CHROMA_RUST_BINDINGS_TEST_ONLY=1 pytest chromadb/test/property/test_cross_version_persist.py (after building/installing the wheel)

This should unblock the 3.14 cross-version CI path from our side. Is there anything else you want me to do to get this merged?

@kylediaz kylediaz force-pushed the fix-python-3.14-pydantic-v2 branch from 808c452 to bef3358 Compare March 2, 2026 07:52
@kylediaz
Copy link
Copy Markdown
Contributor

kylediaz commented Mar 2, 2026

Hey @basnijholt
thank you for helping us with this! sorry for messing up your branch there for a bit. I tested it and I approve of your changes, but I'm going to get further review first before we merge.
don't worry about the gcs test. we expect it to fail for you -- external contributors don't have the correct credentials. we'll merge it anyway.

@basnijholt
Copy link
Copy Markdown
Contributor Author

Great!

You only lost this commit on the force push 808c452.

@kylediaz
Copy link
Copy Markdown
Contributor

kylediaz commented Mar 2, 2026

your PR was good as-is. It will fail if we add python 3.14, but that is not because of your code, it's because of how test_cross_version_compat works. this test verifies migrations across chroma versions work. it will fetch the latest release from pypi, but the latest release is clearly in a broken state. rather than you needing to fix the test, we need to fix the package. sorry about this.

@kylediaz kylediaz self-requested a review March 2, 2026 19:29
@HammadB HammadB merged commit 52f6ff1 into chroma-core:main Mar 2, 2026
63 of 65 checks passed
@kylediaz
Copy link
Copy Markdown
Contributor

kylediaz commented Mar 2, 2026

@basnijholt thanks! we're going to make a release for this fix ASAP

basnijholt added a commit to basnijholt/chroma that referenced this pull request Mar 3, 2026
`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.
@basnijholt
Copy link
Copy Markdown
Contributor Author

@kylediaz I ran into a small issue with this change now. I opened a followup here #6535.

The test shows what currently fails on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Chroma import fails on python 3.14.2 and pydantic 2.12+

6 participants