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

Improve Pydantic v1/2 cross-compatibility #101

Merged
merged 10 commits into from
Feb 4, 2024
Merged

Conversation

hrshdhgd
Copy link
Contributor

@hrshdhgd hrshdhgd commented Feb 2, 2024

Update @validator decorator to @field_validator since the former will be deprecated/removed in future versions.

Warning that triggered this PR:

python3.10/site-packages/curies/api.py:253
../site-packages/curies/api.py:253: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/
    @validator("prefix_synonyms")  # type:ignore

Solution:
~@validator~ => @field_validator

@hrshdhgd
Copy link
Contributor Author

hrshdhgd commented Feb 2, 2024

This may be a crude solution to comply with Pydantic 1.x. I'll leave it upto you @cthoyt, to disregard PR or merge it.

@hrshdhgd hrshdhgd closed this Feb 2, 2024
@hrshdhgd hrshdhgd reopened this Feb 2, 2024
@cthoyt
Copy link
Member

cthoyt commented Feb 2, 2024

@hrshdhgd do you know if there's a pydantic compatibility layer package (like six for the python 2->3 transition)? There are so many people that would benefit from not having to re-think this over and over again

@hrshdhgd
Copy link
Contributor Author

hrshdhgd commented Feb 2, 2024

I think as per pydantic docs, there is bump-pydantic

@hrshdhgd
Copy link
Contributor Author

hrshdhgd commented Feb 2, 2024

I ran bump-pydantic src/curies and this is what I got: https://github.com/hrshdhgd/curies/pull/1/files#diff-155777c613bd355b6a0a9df37a38484289b2f70f971bf6353cb1560ac1415a6b

I also undid everything from this PR and ran bump-pydantic. Instead of refactoring the code to be Pydantic 2 compliant, it just adds a TODOs. e.g.:

# TODO[pydantic]: We couldn't refactor the 'validator', please replace it by 'field_validator' manually.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-validators for more information.

Copy link

codecov bot commented Feb 4, 2024

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

@cthoyt cthoyt changed the title Update @validator decorator to @field_validator since the former will be deprecated/removed in future versions. Improve Pydantic v1/2 cross-compatibility Feb 4, 2024
@cthoyt
Copy link
Member

cthoyt commented Feb 4, 2024

@hrshdhgd that wasn't what I was thinking - rather, I was wondering if there was re-usable code that wraps the logic for writing cross-compatible pydantic models, not if there was code for upgrading

i found https://github.com/pyapp-kit/pydantic-compat btw, seems a bit heavy so for now I think we can just keep a small compatibility layer internal in curies

@cthoyt cthoyt merged commit d2f51d5 into biopragmatics:main Feb 4, 2024
8 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