RWTH-EBC/FiLiP

Migrate to pydantic v2

Closed this issue · 8 comments

Is your feature request related to a problem? Please describe.
Pydantic V2 is out!
https://pypi.org/project/pydantic/
https://docs.pydantic.dev/latest/

It has a fresh core and promises to be multiple times faster! Hence, it would be great to migrate step by step.

Describe the solution you'd like
Migrate step by step and substitute the deprecated functions by the new once.
Pydantic provides a migration guide for this. https://docs.pydantic.dev/latest/migration/

The effort may be relatively small, but definitely worth it.
Otherwise, the library may be stuck in the past.

@djs0109 What do you think? It would definetly mean a major release to the whole library due to breaking changes.

Nice! I think we should definitely move forward. @tstorek Do you think it is worth waiting for the migration tool?

This is connected to #197 as pydantic-settings is now a separated package. Hence, #197 will fix the symptoms but not the general problem. I suggest to do the migration relatively quickly. By setting up a project for this. @djs0109, if you require support, let me know. I can help out with answering questions on the original architecture and smaller issues, but cannot take the lead here.

Apparently they provide a migration-tool now https://github.com/pydantic/bump-pydantic

@djs0109 I looked into a bit here is the strategy I suggest:

  1. Run bump_pydantic tool on the library
  2. Add `pydantic-settings to setup.py and requirements.txt
  3. Correct all imports for pydantic settings
  4. Run tests and fix deprecation all DeprecationWarnings
  5. Deploy something like black for code-formating. Maybe PyCharm will already help you here.
  6. Do a release and mark the merge as potentially BREAKING CHANGE (as we are not on v1, we can introduce this change as v0.3.0)

The pydantic developers did a very good job here. Hence, migration should not take longer than an hour or so. The good thing is that there a very few breaking changes that will affect further developments. They will see the DeprecationWarnings and need to apply the same strategy. I'd appreciate it if you could do it now than wait!

Cool! I will try this migration tool as soon as possible. Thanks again for providing the strategy!

@tstorek do you know where the regex here comes from? Because Pydantic now also has some problems with it.

@djs0109 that's exactly where I struggle right now see #199. They origin from making the headers fiware_safe. Apparently, they will require a little refactoring :/ That's gonna be a little hazzle.

@tstorek Indeed, there are more works than we might think.