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

Refactor/#233 upgrade pydantic to v2 #235

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

ckunki
Copy link
Contributor

@ckunki ckunki commented Dec 3, 2024

Closes #233
Closes #234

class Message(BaseModel, frozen=True):
__root__: Union[
class Message(RootModel, frozen=True):
root: Union[
Copy link
Collaborator

@tkilias tkilias Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also

https://docs.pydantic.dev/latest/concepts/unions/#discriminated-unions-with-str-discriminators

Pydantic 2 uses this to determine against which model to validate if their is a common string attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See latest Push:

Declared Message.root as union discriminated by message_type:

root = Field(discriminator='message_type')

@ckunki ckunki merged commit 09f1196 into main Dec 3, 2024
23 checks passed
@ckunki ckunki deleted the refactor/#233_Upgrade_pydantic_to_v2 branch December 3, 2024 14:27
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.

Release 1.2.0 Upgrade pydantic to version 2
2 participants