Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for Pydantic v2 (while keeping support for v1 if v2 is not available), including initial work by AntonDeMeester #722

Merged
merged 109 commits into from
Dec 4, 2023

Conversation

tiangolo
Copy link
Member

@tiangolo tiangolo commented Dec 4, 2023

✨ Add support for Pydantic v2 (while keeping support for v1 if v2 is not available)

This includes the commits in the initial work by @AntonDeMeester in #699

  • I reverted some things, refactored some parts, fixed some hidden bugs.
  • Restructured the logic in compat.
  • Updated the methods to be available in both Pydantic v1 and v2.
  • Deprecated old methods (from_orm(), etc), adding deprecation markers (they show up in editors), and refactoring the code to use the new ones.
  • Update the docs to use .model_validate() instead of .from_orm() and .parse_obj().
  • Re-implemented several internal parts to support data updates in .model_validate() and keep compatibility with Pydantic v2 and v1, whichever is installed.
  • Implemented the necessary logic to allow keeping values without defaults without them.
  • Implemented the logic to support SQLAlchemy's custom init overriding while keeping support for non-SQLAlchemy models.
  • Updated all the necessary tests to be compatible with both Pydantic v2 and v1, minimizing the cases where its needed to have separate tests.

farahats9 and others added 30 commits November 13, 2023 10:49
Change imports
Undefined => PydanticUndefined
Update SQLModelMetaclass and SQLModel __init__ and __new__ functions
Update SQL Alchemy type inference
Only need to fix OPEN API things I think
Copy link

github-actions bot commented Dec 4, 2023

📝 Docs preview for commit f1ab6a6 at: https://987b63e3.sqlmodel.pages.dev

Copy link

github-actions bot commented Dec 4, 2023

📝 Docs preview for commit 5f4d502 at: https://e043601e.sqlmodel.pages.dev

Copy link

github-actions bot commented Dec 4, 2023

📝 Docs preview for commit b3fcaf0 at: https://d531680f.sqlmodel.pages.dev

Copy link

github-actions bot commented Dec 4, 2023

📝 Docs preview for commit f121b00 at: https://31d1b17d.sqlmodel.pages.dev

@tiangolo tiangolo added the feature New feature or request label Dec 4, 2023
@tiangolo tiangolo marked this pull request as ready for review December 4, 2023 14:41
@tiangolo tiangolo merged commit fa2f178 into main Dec 4, 2023
20 checks passed
@tiangolo tiangolo deleted the pv2-c branch December 4, 2023 14:42
@CyberFlameGO
Copy link

Oh sweet!!

@Matthieu-LAURENT39
Copy link
Contributor

Really amazing news, thanks for all the work that went into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants