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

Start supporting pydantic v2 #382

Closed
Hofer-Julian opened this issue Jul 3, 2023 · 7 comments
Closed

Start supporting pydantic v2 #382

Hofer-Julian opened this issue Jul 3, 2023 · 7 comments
Labels
dependencies Pull requests that update a dependency file python Relates to one of the Ribasim python packages

Comments

@Hofer-Julian
Copy link
Contributor

pydantic v2 is now out with a lot of nice things, most notably higher speed.

I think we will want to support v2 as fast as possible, but depending on the amount of work, it would be nice to continue supporting v1 as well.
If we don't do that, packaging Ribasim Python on Deltaforge will be hard to do in the near future because of version requirement conflicts.

The migration guide can be found here: https://docs.pydantic.dev/latest/migration/

@Hofer-Julian Hofer-Julian added python Relates to one of the Ribasim python packages dependencies Pull requests that update a dependency file labels Jul 3, 2023
@github-project-automation github-project-automation bot moved this to To do in Ribasim Jul 3, 2023
@Hofer-Julian
Copy link
Contributor Author

Fully moving to pydantic v2 depends on machow/quartodoc#211

@visr visr mentioned this issue Sep 12, 2023
@evetion
Copy link
Member

evetion commented Sep 12, 2023

And on Pandera, which has a Pydantic V2 compatible version coming in October at the earliest (and we'll have to test it first).

@visr
Copy link
Member

visr commented Oct 16, 2023

Pandera now supports pydantic v2 as of v0.17: https://github.com/unionai-oss/pandera/releases/tag/v0.17.0
Quartodoc merged support a few days ago to main, so the upcoming release after v0.6.3 should have it.

@visr
Copy link
Member

visr commented Oct 16, 2023

Ok our dependencies are ready, now we just need to update.

I tried pixi add pydantic=2 and that works, only it causes ribasim-python tests to fail.

E       pydantic_core._pydantic_core.ValidationError: 5 validation errors for Model
E       outlet
E         Field required [type=missing, input_value={'modelname': 'basic', 'n...='debug', timing=False)}, input_type=dict]
E           For further information visit https://errors.pydantic.dev/2.4/v/missing
E       discrete_control
E         Field required [type=missing, input_value={'modelname': 'basic', 'n...='debug', timing=False)}, input_type=dict]
E           For further information visit https://errors.pydantic.dev/2.4/v/missing
E       pid_control
E         Field required [type=missing, input_value={'modelname': 'basic', 'n...='debug', timing=False)}, input_type=dict]
E           For further information visit https://errors.pydantic.dev/2.4/v/missing
E       user
E         Field required [type=missing, input_value={'modelname': 'basic', 'n...='debug', timing=False)}, input_type=dict]
E           For further information visit https://errors.pydantic.dev/2.4/v/missing
E       solver
E         Field required [type=missing, input_value={'modelname': 'basic', 'n...='debug', timing=False)}, input_type=dict]
E           For further information visit https://errors.pydantic.dev/2.4/v/missing

python\ribasim_testmodels\ribasim_testmodels\basic.py:196: ValidationError

I don't really understand why since these are declared as Optional. Probably best to wait until @evetion tackled #630. @evetion I don't know if you plan to upgrade as part of the redesign, but it's good to know that you could start using pydantic v2 features. You could use d736371 for the dependency upgrade if needed.

@Hofer-Julian
Copy link
Contributor Author

Optional (or T | None) behaves differently with pydantic 2 (another reason why we should drop the misleading Optional and use the new syntax instead)

@Hofer-Julian
Copy link
Contributor Author

@visr that is the change: https://docs.pydantic.dev/latest/migration/#required-optional-and-nullable-fields

TLDR: just add a default value of None and you get the old behavior

@evetion evetion moved this from To do to 🏗 In progress in Ribasim Nov 9, 2023
@evetion evetion moved this from 🏗 In progress to ✅ Done in Ribasim Nov 16, 2023
@visr
Copy link
Member

visr commented Nov 16, 2023

Fixed in #731

@visr visr closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file python Relates to one of the Ribasim python packages
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants