-
Notifications
You must be signed in to change notification settings - Fork 120
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
Refactoring Redis OM Python to use pydantic 2.0 types and validators #603
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, I will build a basic app using Pydantic 2.0 and provide some feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tons of work here @slorello89 ! Kudos for grinding through. When will we drop pydantic <= 1.x.x support? LangChain has also had to fight this battle.
from pydantic.version import VERSION as PYDANTIC_VERSION | ||
from typing_extensions import Annotated, Literal, get_args, get_origin | ||
|
||
|
||
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's helpful, I have seen some shim implementations that just use try except.. but this may not necessarily be better. Just offering some other ways to approach this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try/except approach makes me feel icky. Are we thinking of dropping Pydantic 1.0 support completely? It's seems a lot of project are doing that nowadays.
@tylerhutcherson - I think a reasonable cutoff is whenever pydantic removes the v1 shim to discontinue support for v1. I think that might be coming sooner rather than later(I think they are stopping bug fixes after June). |
Thanks for looking into this! This would be great to have soon, given pydantic recently released 2.7.0 few days ago :) would make this library a lot more useful in projects where I can't downgrade pydantic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked through made some take or leave style comments. Seems like there might be a couple dangling comments/lines
aredis_om/model/model.py
Outdated
@@ -1156,7 +1203,7 @@ def Field( | |||
vector_options=vector_options, | |||
**current_schema_extra, | |||
) | |||
field_info._validate() | |||
# field_info._validate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this fire? Or are you doing validate elsewhere? Otherwise, no need for comment probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there might be a couple dangling comments. Other than that LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
With #533 it became possible to use Redis OM Python in an environment where pydantic 2.0 was installed, however this leaned completely on the pydantic v1 shim, consequentially this meant that if you tried to use any of the pydantic 2.0 types or validators produce errors-a-plenty, see: #602, #601, #590, #572, #571, #546, and many more
Pydantic V1 -> Pydantic V2 was described as a "ground up rewrite" by the pydantic team, and it's apparent that it was, however they have also stated that while they will be shipping major versions every year going forward that future migrations should not be nearly as painful
the tact projects like FastAPI took was to use the shim in the inverse (import v1 types from their old places if your pydantic version is V1, use v2 types if pydantic version is v2), which this PR adapts us towards.
If you only use pydantic 1.x, there should be no breaking changes in here, the shim should include the correct fields for you and the code should be backwards compatible, however if you are using pydantic 2.0 in your app, there will be breaks going from redis om python 0.2.x -> 0.3.x. namely. In short, anything that comes up in the pydantic 2.0 migration guide is liable to be an issue for someone migrating. Some highlights:
ValidationError
to the pydantic 2.xValidationError
.Would like some eyes from our end (namely @banker, @bsbodden, @tylerhutcherson). As well as feedback from anyone in the community who might have interest.