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

Pydantic 2.0 Released #13

Open
raratiru opened this issue Jul 26, 2023 · 1 comment
Open

Pydantic 2.0 Released #13

raratiru opened this issue Jul 26, 2023 · 1 comment

Comments

@raratiru
Copy link

A new major release of pydantic is published.

There is a migration guide too:

https://docs.pydantic.dev/latest/migration/

Will there be an upgrade or will pull requests be accepted?

@westurner
Copy link

westurner commented Oct 20, 2024

  • bump-pydantic auto-upgrades some pydantic v1 code to pydantic v2

    pip install bump-pydantic
    bump-pydantic pydantic_schemaorg/
    bump-pydantic src/
  • sed-replace pydantic imports

    • things could be upgraded one at a time if necessary;
      just remove the .v1 when the tests pass

    • this should work with pydantic v1 >= v1.10.17 and v2
      https://docs.pydantic.dev/latest/migration/#using-pydantic-v1-features-in-a-v1v2-environment :

      The Pydantic V2 package also continues to provide access to the Pydantic V1 API by importing through pydantic.v1.

      For example, you can use the BaseModel class from Pydantic V1 instead of the Pydantic V2 pydantic.BaseModel class:

      from pydantic.v1 import BaseModel
    git status; # git stash || git commit -a -m
    sed -i -e 's/pydantic.BaseModel/pydantic.v1.BaseModel/g' \
           -e 's/pydantic.fields/pydantic.v1.fields/g' \
           -e 's/from pydantic import fields/from pydantic.v1 import fields/g' \
           -e 's/from pydantic import BaseModel/from pydantic.v1 import BaseModel/g'
    git diff
    grep -rni BaseModel
    grep -rni 'from pydantic import' | grep -E 'BaseModel|fields'
    grep -rni 'from pydantic import' | grep -E  'validators'
  • pydantic v1 -> v2 migration guide:
    https://docs.pydantic.dev/latest/migration/

westurner added a commit to westurner/pydantic_schemaorg that referenced this issue Oct 20, 2024
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

No branches or pull requests

2 participants