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

Change Pydantic from_orm to model_validate (#284) #285

Merged
merged 9 commits into from
Jul 11, 2024
Merged

Change Pydantic from_orm to model_validate (#284) #285

merged 9 commits into from
Jul 11, 2024

Conversation

Bvr4
Copy link
Contributor

@Bvr4 Bvr4 commented Jun 21, 2024

Pull Request

Description

This PR refers to the issue #284 : from_orm method is deprecated in pydantic V2

I updated the models and tests that called the deprecated pydantic method from_orm. They now call model_validate as advised in the Pydantic migration guide.

The Forecast and ForecastValue models had methods that overwrote the pydantic from_orm method. I leaved those methods in the models, but they now call model_validate instead of from_orm. I also created model_validate methods for those classes, having the same behavior as calling from_orm.

How Has This Been Tested?

I tested via the test framework as seen in the readme file. As the modification are minors, it should be enough.

  • Yes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation > not needed
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

Bvr4 and others added 7 commits June 17, 2024 16:40
…lue models (#284)

Updated from_orm class method in Forecast and ForecastValue models, so they call model_validate instead of the deprecated from_orm method.
Created a class method model_validate in Forecast and ForecastValue models, so they work as from_orm class methods worked.
Updated Forecast and ForecastValue models from_orm call to model_validate call.
Updated Forecast and ForecastValue models from_orm call to model_validate call.
Created model_validate_latest method that does the same thing as from_orm_latest. So it is consistent to the syntax of pydantic V2
@Bvr4
Copy link
Contributor Author

Bvr4 commented Jun 28, 2024

Hello,

The tests failed because I use "from_attributes: bool | None = None" typing annotation, as I assumed the project used python >= 3.10.

I can change that annotation for compatibility issues if it is not the case.

@peterdudfield
Copy link
Contributor

Hello,

The tests failed because I use "from_attributes: bool | None = None" typing annotation, as I assumed the project used python >= 3.10.

I can change that annotation for compatibility issues if it is not the case.

Thanks so much for this, really helpful doing all this.
would you be able to help get the test working? Perhaps just chaning python3.9 to python3.10 in the docker file

@peterdudfield peterdudfield merged commit 66f3328 into openclimatefix:main Jul 11, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants