cloudevents / sdk-python

Python SDK for CloudEvents
https://pypi.org/p/cloudevents/
Apache License 2.0
266 stars 53 forks source link

Adds a pydantic V2 compatibility layer #218

Closed febus982 closed 10 months ago

febus982 commented 10 months ago

Fixes #215

Changes

Adds a compatibility layer allowing to install the SDK together with pydantic v2, while still using the v1 implementation. Further improvements would be a native pydantic v2 implementation.

One line description for the changelog

Allows to install the SDK together with pydantic v2.

duglin commented 10 months ago

ping @Klaudioz @denismakogon @xSAVIKx @cumason123

febus982 commented 10 months ago

There’s a typing issue, I think it’s safe to ignore it, is it fine to ignore it? (don't want to trigger too many minutes on workers)

I have started working on the native Pydantic V2 implementation.

xSAVIKx commented 10 months ago

@febus982, thx for the PR! It's awesome that you jumped in and prepared one. I believe that's the best possible approach to bring v2 support fast. IDK whether the v1 compatibility layer of Pydantic is going to last long and whether it has comparable performance as "native" v2, but IMO that's good enough already.

As for the tests, with the change you made, I believe our CI is now only running tests against v2 and is not running tests against v1 anymore. Having tests with both v1 and v2 versions of Pydantic is gonna require quite some more changes to the way the repo is managed.

Regarding the typings issue, I believe we'll need to suppress that one, but not just ignore it. Can you please suppress it with # type: ignore?

febus982 commented 10 months ago

Hey @xSAVIKx

Regarding the typings issue, I believe we'll need to suppress that one, but not just ignore it. Can you please suppress it with # type: ignore?

Yes, I meant ignore for us humans, and suppress it. I'll add # type: ignore

As for the tests, with the change you made, I believe our CI is now only running tests against v2 and is not running tests against v1 anymore. Having tests with both v1 and v2 versions of Pydantic is gonna require quite some more changes to the way the repo is managed.

If this is very important I can try to see if I can configure different tox environments, however as pydantic V1 development is stopped (except for critical bug fixes and security issues) the double time required for tests is something to be considered. Let me know if you want me to address this as well.

xSAVIKx commented 10 months ago

Neah, I just checked the internals of the v1 compatibility layer and it feels like they just copied over the whole v1 library 😅 just fixing typings to please mypy and make the check pass is good enough

febus982 commented 10 months ago

@xSAVIKx I think it's ready to go (hopefully tests will pass, tox is happy on my local machine)