red-bird icon indicating copy to clipboard operation
red-bird copied to clipboard

Pydantic v2 Support

Open Jypear opened this issue 1 year ago • 2 comments

Creating this as a work in progress/draft PR to get the ball rolling on the pydanticv2 migrations. There's potentially a breaking change (changing the model_orm argument for SQLRepo to just orm). Using "model_" now clashes with a pydantic protected Namespace. We might be able to get round this using a Field alias, but it would require some testing to see if it would still cause the clash.

Tests are still failing at this point but Memory Repo and SQLRepo are running in a basic test.

Will continue to work on this over the weekend hopefully.

Jypear avatar Jul 28 '23 22:07 Jypear

Hi @Miksus,

Just to let you know I've now marked this PR ready for review. I've got rid of all failing tests and deprecation warnings (bar one, I have no idea where this is coming from). There will also be some outstanding issues, this project uses pydantic-sqlalchemy, which ties pydantic to version 1. There is a PR which I have dropped a comment on to see if that can get pushed out.

Breaking changes

This PR contains breaking changes for anybody that consumes this, so you may have to version this appropriately.

  • 'model_orm' has been changed to 'orm' in the SQLRepo. This is because 'model_' is now a protected namespace inside pydantic.
  • This is yet to be tested, but due to the way that pydantic now handles the Optional type and default arguments, I'm not sure if that will have a lasting affect on optional fields inside Repos

The rest are just migration pieces. Please feel free to pull me up on anything in a review when you get chance.

Jypear avatar Oct 06 '23 17:10 Jypear

@Jypear, thanks for your work on this, I've switched to your fork for my projects. To avoid the model_orm breaking change, have you considered removing model_ from the set of Pydantic protected namespaces on the SQLRepo class? https://github.com/pydantic/pydantic/discussions/7121#discussioncomment-6849030

gregoryfoster avatar Aug 21 '24 21:08 gregoryfoster