madpah / serializable

Pythonic library to aid with serialisation and deserialisation to/from JSON and XML.
https://py-serializable.readthedocs.io/
Apache License 2.0
5 stars 4 forks source link

fix: date/time deserialization with fractional seconds #138

Closed ILikeToFixThings closed 1 month ago

ILikeToFixThings commented 1 month ago

Hi,

Currently on Python 3.10 and earlier there is an exception thrown if you try to parse a JSON file with more than 6 fractional seconds (the decimals) in a JSON file. ISO8601 datetimes are allowed to have any number of fractional seconds but the regex fix applied by this library to allow Python to parse ISO8601 timestamps that is needed pre Python 3.11 due to weirdness around Pythons ISO parsing requiring either 0 or 6 fractional seconds currently only pads the fractional seconds if required and does not truncate if the timestamp is too long which was causing me issues parsing a JSON SBOM file generated by cargo-cyclonedx which includes 9 decimal places on its timestamp for some reason. This is only an issue pre Python 3.11 since in 3.11 they made datetime.fromisoformat ISO compliant.

I have added some tests which showcase the issue and applied a fix to the padding code of datetime deserialization.

jkowalleck commented 1 month ago

tried to consolidate the python 3.11 compatibility layer via https://github.com/madpah/serializable/pull/138/commits/72ce000f0fb4b33343f1a981fabbf6228e41d29b This seams to break something, will investigate and fix

jkowalleck commented 1 month ago

@ILikeToFixThings I did a consolidation of your changes. could you review?

jkowalleck commented 1 month ago

@madpah could I ask you for a review?

ILikeToFixThings commented 1 month ago

@ILikeToFixThings I did a consolidation of your changes. could you review?

Looks good to me!

jkowalleck commented 1 month ago

@ILikeToFixThings ,

Thank you so much for bringing this issue up and providing fixes for it.

Your work resulted in the published release: https://github.com/madpah/serializable/releases/tag/v1.1.2

madpah commented 1 month ago

And thanks too @jkowalleck ;-)