openclimatefix / nowcasting_datamodel

Datamodel for the nowcasting project
6 stars 6 forks source link

Change Pydantic from_orm to model_validate (#284) #285

Closed Bvr4 closed 2 months ago

Bvr4 commented 3 months ago

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.

Checklist:

Bvr4 commented 3 months ago

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 commented 2 months ago

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