codello / Motor-ODM

A MongoDB ODM based on Motor and Pydantic.
MIT License
17 stars 5 forks source link

ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' #32

Open mattlgroff opened 2 months ago

mattlgroff commented 2 months ago

Error when using Motor ODM with latest Pydantic 2.8.2 (and maybe earlier)

ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' 
(/app/.venv/lib/python3.12/site-packages/pydantic/main.py)
dependencies = [
    "motor-odm>=0.1.dev0",
    "motor>=3.5.1",
    "pydantic>=2.8.2",
]
mattlgroff commented 2 months ago

https://github.com/pydantic/pydantic/issues/6381

This issue suggesting updating the import to:

from pydantic._internal._model_construction import ModelMetaclass