Skip to content

🐛 fix: serialize Pendulum zero Duration as valid ISO 8601 'P0D' #320

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

Merged
merged 3 commits into from
May 19, 2025

Conversation

dreglad
Copy link
Contributor

@dreglad dreglad commented May 19, 2025

This PR fixes the serialization of zero-value Pendulum durations. Previously, serializing a zero duration produced the invalid ISO 8601 string 'P', which caused validation errors on deserialization. Now, zero durations are correctly serialized as 'P0D'.

Before

TestModel(delta_t=Duration(0)).model_dump_json()
# Output: {"delta":"P"}
# Validation error on reload

After

TestModel(delta_t=Duration(0)).model_dump_json()
# Output: {"delta":"P0D"}
# No validation error

Copy link
Collaborator

@yezz123 yezz123 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@yezz123 yezz123 merged commit cdd564f into pydantic:main May 19, 2025
10 checks passed
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.

2 participants