JSON decimal values should be parsed as Python decimal.Decimal
in targets when reading Singer messages
#344
Labels
decimal.Decimal
in targets when reading Singer messages
#344
Migrated from GitLab: https://gitlab.com/meltano/sdk/-/issues/346
Originally created by @edgarrmondragon on 2022-03-09 16:17:31
Summary
JSON decimal values should be parsed as Python
decimal.Decimal
in targets when reading Singer messages.Steps to reproduce
Try piping a tap that outputs similar to
{"type": "number", "multipleOf": "0.001"}
to a target that performs JSON schema validation. Values that should pass validation will fail.What is the current bug behavior?
Decimals are loaded as
float
values which may cause problems when their precision is important, e.g. when validating against JSON schema `multipleOf' .What is the expected correct behavior?
Decimals should be loaded as
decimal.Decimal
to preserve precision.Relevant logs and/or screenshots
Possible fixes
The
jsonschema
library dev recommends loading JSON decimals as Pythondecimal.Decimal
: python-jsonschema/jsonschema#810 (comment).Using
json.loads(..., parse_float=decimal.Decimal)
in https://gitlab.com/meltano/sdk/-/blob/b394e1a9c0d68a554640974c05be1c9d548270ee/singer_sdk/io_base.py#L77 should fix the issue.The text was updated successfully, but these errors were encountered: