Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Pydantic 2 Support #75

Open
etimberg opened this issue Oct 12, 2023 · 7 comments
Open

Pydantic 2 Support #75

etimberg opened this issue Oct 12, 2023 · 7 comments

Comments

@etimberg
Copy link

I was testing out djantic with pydantic 2.4.2 and ran into an error caused by an import that was removed from pydantic.

  File "/usr/local/lib/python3.11/site-packages/djantic/main.py", line 12, in <module>
    from pydantic import BaseModel, ConfigError, create_model
ImportError: cannot import name 'ConfigError' from 'pydantic' (/usr/local/lib/python3.11/site-packages/pydantic/__init__.py)

The root cause of this appears to be that ConfigError was removed from pydantic during the v1 -> v2 transition as mention in the migration guide

@giulioindev
Copy link

giulioindev commented Oct 22, 2023

Please can this issue be solved? Also the Pydantic’s 'from_orm' method has been replaced with the 'model_validate' with a proper config for the model

@etimberg
Copy link
Author

I tried patching the ConfigError issue, but immediately ran into another import problem. ModelMetaClass, used here has been made private

@giulioindev
Copy link

Now should be _model_construction.ModelMetaclass

@etimberg
Copy link
Author

Yup, but I also read pydantic/pydantic#6381 where the maintainers of pydantic mention that they want to be able to change it without it being a breaking change. If possible, it might be good to refactor djantic to avoid using it directly.

@wjurkowlaniec
Copy link

+1 for this. I'll be doing migration from Django to FastAPI and switching to V2 of Pydantic could be great

@joepreludian
Copy link

Is there someone looking at this issue already? +1 for this.

@jonathan-s
Copy link

Djantic now supports pydantic 2 in a fork that I made #79

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants