Skip to content

pydantic v1 => v2 - #7

Merged
dovinmu merged 10 commits into
mainfrom
fix/pydantic-v2
Apr 10, 2026
Merged

pydantic v1 => v2#7
dovinmu merged 10 commits into
mainfrom
fix/pydantic-v2

Conversation

@dovinmu

@dovinmu dovinmu commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Migrate all pydantic v1 patterns to v2, required because chromadb depends on pydantic>=2 which conflicts with this project's
pydantic<v2 pin.

What changed

This is a mechanical migration with no behavioral changes:

  • pyproject.toml: "pydantic<v2" → "pydantic>=2.0"
  • @validator("*") → @model_validator(mode="before"): 6 DB configs (api, aws_opensearch, doris, milvus, oss_opensearch, qdrant_cloud,
    tidb) had per-field empty-string validators; these become a single mode="before" model validator with identical logic
  • @root_validator → @model_validator(mode="before"): oss_opensearch engine name mapping
  • @validator("field") → @field_validator("field", mode="before"): oss_opensearch quantization type coercion, dataset size
    verification
  • .dict() → .model_dump(), .json() → .model_dump_json(): 9 call sites
  • PrivateAttr → ClassVar: _size_label dicts on dataset classes (7 sites)
  • int | None → int | None = None: ~40 Optional fields that now require explicit defaults in v2
  • model_config = ConfigDict(validate_default=True): ensures SecretStr fields with string defaults are coerced at construction time
  • MetricType = "cosine" → MetricType = MetricType.COSINE: chroma config (enum, not bare string)
  • Lint fixes: import sorting, unused import removal, EM102 compliance, black reformatting

Also incorporates the _httpx_host() fix from main (IPv6 localhost resolution on macOS).

What did NOT change

  • No benchmark logic, dataset handling, or result reporting was modified
  • No new dependencies
  • The endee==0.1.10 pin is preserved with a TODO to check v2 compat

Test plan

  • CI passes (lint + unit tests)
  • Run a VectorDBBench benchmark to verify no runtime regressions

dovinmu and others added 10 commits March 25, 2026 13:51
- Auto-negotiate external index with/without field parameter to support
  both old binaries (require field) and new source (reject field with external)
- Fix chroma bench script to use uv pip instead of missing bin/pip
- Add environs to chroma venv deps
- PYTHON defaults to .venv/bin/python instead of hardcoded home dir
- antfly client skips table/index creation when they already exist
  (enables --skip-load reuse runs)
chromadb requires pydantic>=2 but the project pinned pydantic<v2, causing
an ImportError on the chroma benchmark. This migrates all pydantic v1
patterns to v2: @validator("*") → @model_validator(mode="before"),
@root_validator → @model_validator, .dict() → .model_dump(),
.json() → .model_dump_json(), PrivateAttr → ClassVar, and adds
explicit = None defaults for Optional fields (required in v2).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add validate_default=True to DBConfig so SecretStr fields with string
defaults (e.g. host: SecretStr = "localhost") are properly coerced
during construction. Without this, pydantic v2 skips validation on
defaults, leaving raw strings that crash model_dump_json serialization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve conflicts:
- Makefile: accept deletion (superseded by parent repo's Makefile)
- antfly.py: take fix/pydantic-v2 side (direct store search, index
  reuse, field compat) and incorporate _httpx_host() fix from main
  for macOS IPv6 localhost resolution

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add minimal Makefile with lint and unittest targets (CI needs these)
- Fix black formatting (blank lines removed during migration)
- Fix ruff: sort imports, remove unused SecretStr import, extract
  f-strings from exception constructors (EM102)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dovinmu
dovinmu merged commit c636ff5 into main Apr 10, 2026
4 checks passed
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.

1 participant