Skip to content

fix: restore plain Pydantic model identities - #1947

Open
yaodong-shen wants to merge 1 commit into
datachain-ai:mainfrom
yaodong-shen:fix/1910-restore-pydantic-model-identity
Open

fix: restore plain Pydantic model identities#1947
yaodong-shen wants to merge 1 commit into
datachain-ai:mainfrom
yaodong-shen:fix/1910-restore-pydantic-model-identity

Conversation

@yaodong-shen

Copy link
Copy Markdown

Fixes #1910.

When a dataset schema is read in a fresh process, plain Pydantic models are not registered in ModelStore, so the schema previously rebuilt same-named dynamic models. This restores an already loaded original model only when its stored field specification (including nested Pydantic models) matches.

The resolver only inspects sys.modules and existing BaseModel subclasses; it never imports a module named by dataset metadata. A same-named model with a mismatched schema is rejected with a warning and the existing dynamic rebuild path is retained.

Tests:

  • pytest tests/unit/lib/test_signal_schema.py -q
  • ruff check src/datachain/lib/signal_schema.py tests/unit/lib/test_signal_schema.py
  • ruff format --check src/datachain/lib/signal_schema.py tests/unit/lib/test_signal_schema.py

This complements #1877, which handles conflicting already-registered models.

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.

Nested pydantic models lose their class identity in another process

1 participant