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

[BugFix] Fix Serialization of Computed Properties in BaseModel #485

Merged
merged 2 commits into from
May 1, 2024

Conversation

rahul-tuli
Copy link
Member

Description:

A bug was identified where computed properties in the base model were not serialized correctly due to an overridden dict() method. The method was initially designed to inject properties, but since the introduction of model_dump as a naming convention, it no longer executed the necessary code when yaml() was called.

Fixes Included:

  • Introduced an alias for dict() that delegates to model_dump to resolve naming conflicts.
  • Used the computed_fields decorator from Pydantic v2 for properties that require serialization.
  • Got rid of original PropertyBaseModel

Test Plan:

  • Added a new unit test to ensure that the model_dump() method correctly returns a dictionary with the computed fields. This test fails on the main branch but passes on this branch.
  • Confirmed that the original test failures are resolved with this update.

@rahul-tuli rahul-tuli merged commit 6ae1b94 into main May 1, 2024
4 of 5 checks passed
@rahul-tuli rahul-tuli deleted the pydantic-serialization-fix branch May 1, 2024 17:53
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.

3 participants