Serialization -> de-serialisation fails for small timedelta (< 100 microseconds) #3315
Closed
3 tasks done
Labels
bug V1
Bug related to Pydantic V1.X
Checks
Bug
The serialization -> de-serialization of a model with small
timedelta
raises aValidationError
. The de-serialization fails only when thetimedelta
is below 100 microseconds, see the following example:Last line throws the following error:
I believe the error comes from the
parse_duration
function, and in particular the line where the input value is converted tostr
.https://github.com/samuelcolvin/pydantic/blob/c256dccbb383a7fd462f62fcb5d55558eb3cb108/pydantic/datetime_parse.py#L226-L231
Indeed
str(0.0001)
gives"0.0001"
butstr(0.000099)
gives"9.9e-5"
, thus there.match
fails.Changing
value = str(value)
tovalue = "f{value:.6f}"
should fix this. I would be happy to create a PR to solve the issue.System information
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:The text was updated successfully, but these errors were encountered: