Skip to content

Timestamp serialization does not use the canonical representation #854

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

Open
stefan6419846 opened this issue Apr 9, 2025 · 0 comments
Open

Comments

@stefan6419846
Copy link

When doing some analysis regarding timestamps and how they are rendered by pyyaml, we stumbled upon the fact that

def represent_datetime(self, data):
value = data.isoformat(' ')
return self.represent_scalar('tag:yaml.org,2002:timestamp', value)
would always use the space-separated variant instead of the canonical way described in https://yaml.org/type/timestamp.html This broke some tests, as other tools like django-rest-framework and its serializers would use the canonical variant.

Digging through the code, this apparently has always been like this in pyyaml: cc316a4#diff-13bed56fc23472d5ca7cd84fd0428c0d64f18f68591c1c48fbf686c1c253aa1aR192

From the specification, I would have expected the regular ISO8601 variant to be the default:

This can be serialized using a subset of the ISO8601 format and the formats proposed by the W3C note on datetime. In addition, a more relaxed format is also supported for enhanced readability, using white space separation.

For now, we are working around this with a custom dumper, but I would expect the reference library to follow its own specification, especially going the canonical way.

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

No branches or pull requests

1 participant