Closed Bvr4 closed 2 months ago
I would like to work on this issue, can it be assigned to me ?
I would like to work on this issue, can it be assigned to me ?
of course - thanks @Bvr4
It might be worth checking https://github.com/openclimatefix/pv-site-datamodel this repo, to see if any pydantic upgrades need to happen
I did a quick search on this particular from_orm method, it is used in several repos (nowcasting-metrics, ocf_datapipes, uk-analysis-dashboard, GSPConsumer...) I'll do a detailed check on pv-site-datamodel later.
I have a question relative to this issue. The pydantic migration guide advises us to use model_validate instead of the deprecated from_orm method. In the Forecast model, there is a from_orm_latest method. Would it be judicious to rename it model_validate_latest ? I think it would be more consistent.
Just to check, does model_validate change from sql to pydantic? I think that what from_orm did?
Yes, model_validate transforms any object (in this case, an ORM instance from SQL) into a pydantic object, after validations. It works in the same way as from_orm or parse_obj in V1. I don't know why they deprecated from_orm though.
The Forecast and ForecastValue models overwrites pydantic from_orm method. We can change that so they overwrites the model_validate method. But if from_orm method is called by other projects, we might face unexpected behaviors (as it seams from_orm can still be called with pydantic V2, but raises DeprecationWarnings). Maybe we could keep overwrited from_orm method aside a new overwrited model_validate method ? So we won't face problems if other projects still uses from_orm for this models.
The Forecast and ForecastValue models overwrites pydantic from_orm method. We can change that so they overwrites the model_validate method. But if from_orm method is called by other projects, we might face unexpected behaviors (as it seams from_orm can still be called with pydantic V2, but raises DeprecationWarnings). Maybe we could keep overwrited from_orm method aside a new overwrited model_validate method ? So we won't face problems if other projects still uses from_orm for this models.
Yea, thats a good idea. Yea perhaps just this line could be updated, but keep that function
It might be worth checking https://github.com/openclimatefix/pv-site-datamodel this repo, to see if any pydantic upgrades need to happen
The use of pydantic is quite limited in this repo, there's no upgrade needed to match pydantic V2 recommendations.
While working on the issue #281, I saw that the from_orm method from pydantic V1 is deprecated in pydantic V2. This method is still present in some models.
It would be interesting as well to verify if other deprecated pydantic methods are still presents in the models.