-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[wip] Pydantic v2 #2751
base: main
Are you sure you want to change the base?
[wip] Pydantic v2 #2751
Conversation
79c82a0
to
1934f57
Compare
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.
Review checkpoint 1: Complete ✅
the "model_post_init"
in the State was one thing that tripped me up last time i was working in this code.
@@ -271,11 +277,18 @@ def __init__(self, *args, **kwargs): | |||
field_type = EventChain | |||
elif key in props: | |||
# Set the field type. | |||
field_type = fields[key].type_ | |||
field_type = fields[key].annotation |
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.
in other places in the code annotation
seems to be a function? 🤔 not sure if this is incorrect, but leaving myself a bookmark with this comment
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.
Yeah, cs_obj = field.annotation()
is there to initialize default values iirc. Maybe pydantic provides smth like get_field_default
which handles default
and default_factorys
for us?
return super().get_value(value.__wrapped__) | ||
return super().get_value(value) | ||
|
||
def _get_value(self, value: Any, **kwargs) -> Any: |
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.
why a new function? is this just WiP artifacts?
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.
_get_value
is there to allow unwrapping the MutableProxy
s in pydantics serialization. There should be a better way to do this.
Funny sidenote: While _get_value
is deprecated by pydantic, they somehow seem to rely on it for serialization.
f74f33d
to
1dea3b1
Compare
141be37
to
16a7c1f
Compare
@masenf should we revisit this? Or do you plan to migrate |
#1539
Heavily inspired by @masenf's pydantic branch (https://github.com/reflex-dev/reflex/tree/masenf/pydantic-v2)