Menu

#365 Unable to dump mutated TimeStamp objects

closed
nobody
None
minor
bug
2021-03-29
2020-11-23
No

I observed that mutating TimeStamp objects produced by ruamel.yaml results in data that ruamel.yaml cannot dump.

To reproduce run the following code using the latest version (0.16.12):

from ruamel.yaml import YAML
from io import StringIO

out = StringIO()

yaml = YAML()
t = yaml.load('2020-11-10 18:00:00+00:00')

print(repr(t))
t2 = t.replace(second=0)
print(repr(t2))
yaml.dump(t2, out)

This will fail with AttributeError: 'TimeStamp' object has no attribute '_yaml'.

Discussion

  • Anthon van der Neut

    I had more or less expected that the fall-through to datetime.datetime.replace() would return a datetime.datetime instance, but instead it does return type(self)(....)

    So the thing to do is add a replace that properly copies the _yaml attribute.

     
  • Anthon van der Neut

    • status: open --> resolved
     
  • Anthon van der Neut

    Fixed in 0.16.13, thanks reporting

     
  • Anthon van der Neut

     
  • Anthon van der Neut

    Fixed in 0.16.13, thanks reporting

     
    ❤️
    1
  • Anton Akhmerov

    Anton Akhmerov - 2021-03-05

    Awesome, thanks!

     
  • Anthon van der Neut

    • status: resolved --> closed
     

Log in to post a comment.