-
Notifications
You must be signed in to change notification settings - Fork 229
Update to Pydantic V2 #588
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
Conversation
I inlined the Pydantic serializer into every generated enum since |
Fwiw if the code is easier to generate/understand use typing_extensions.Annotated. It is already a dep of the project and probably pydantic |
I don't mind either way, your call |
I just discovered the |
code looks fine to me as is :) |
relock and the checks should go green |
Should be fixed |
@Gobot1234 I've resolved conflicts against develop. Is this g2g now? |
CI looks good :) |
Reverted the import change |
|
||
{% endfor %} | ||
{% endif %} | ||
{% for message in output_file.messages %} | ||
@dataclass(eq=False, repr=False) | ||
@dataclasses.dataclass(eq=False, repr=False) |
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 needs reverting
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.
Yup, just caught that, apologies
@Gobot1234 are we all set? Keen to start getting some model validation in my protos 😄 |
Yep, thanks for this! |
@Gobot1234 would you be open to publishing a v2.0.0-beta7? |
If you can write up the changelog I'm happy to merge it (I don't have perms to merge without review) and publish. |
Actually it looks like there’s some weird behaviour with the PLACEHOLDER object. Should that be replaced with default primitive value for the given type? Not sure… |
@@ -1,9 +1,16 @@ | |||
# Generated by the protocol buffer compiler. DO NOT EDIT! | |||
# sources: google/protobuf/any.proto, google/protobuf/api.proto, google/protobuf/descriptor.proto, google/protobuf/duration.proto, google/protobuf/empty.proto, google/protobuf/field_mask.proto, google/protobuf/source_context.proto, google/protobuf/struct.proto, google/protobuf/timestamp.proto, google/protobuf/type.proto, google/protobuf/wrappers.proto | |||
# plugin: python-betterproto | |||
|
|||
# This file has been @generated |
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.
@Gobot1234 I thought you specifically said you didn't want this @generated label on these files during this PR: #568.
I'm opening a PR for a CHANGELOG and bump in version, and wondering if you think this is blocking.
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.
Ah yep good catch, would you mind removing it in your PR so it's easier to merge?
Summary
Updates betterproto to generate data classes for Pydantic V2.
The issues I ran into were:
root_validator
is deprecatedmodel_validate(mode='after')
, required updating the field validator to use getattr on the built modelbetterproto.Enum
was not recognized by Pydantic as an enum type.__get_pydantic_core_schema__
function on every generated Enum class. Open to switching to this.Fixes #530
Checklist