JSON Schema "multipleOf" validation is broken for floats
This lib uses jsonschema validation (https://gitlab.com/meltano/target-csv/-/blob/75c5ceb4df6ffc509243ece2d02be0c8fe69f5fa/target_csv.py#L16), but that doesn't actually work for floats:
target-csv | Traceback (most recent call last):
target-csv | File "/Users/paul/meltano/bi-pipeline/.meltano/loaders/target-csv/venv/bin/target-csv", line 11, in <module>
target-csv | load_entry_point('target-csv==0.2.4', 'console_scripts', 'target-csv')()
target-csv | File "/Users/paul/meltano/bi-pipeline/.meltano/loaders/target-csv/venv/lib/python3.7/site-packages/target_csv.py", line 154, in main
target-csv | input)
target-csv | File "/Users/paul/meltano/bi-pipeline/.meltano/loaders/target-csv/venv/lib/python3.7/site-packages/target_csv.py", line 65, in persist_lines
target-csv | validators[o['stream']].validate(o['record'])
target-csv | File "/Users/paul/meltano/bi-pipeline/.meltano/loaders/target-csv/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 130, in validate
target-csv | raise error
target-csv | jsonschema.exceptions.ValidationError: 2.22 is not a multiple of 0.01
target-csv |
target-csv | Failed validating 'multipleOf' in schema['properties']['tax_savings_percent']:
target-csv | {'inclusion': 'available',
target-csv | 'multipleOf': 0.01,
target-csv | 'type': ['null', 'number']}
target-csv |
target-csv | On instance['tax_savings_percent']:
target-csv | 2.22
This has been raised in the jsonschema lib: https://github.com/Julian/jsonschema/issues/185
In Python you should be able to fix this by casting the raw JSON data to a Decimal, which does not have the same issues.
Another jsonschema implementation seems to have fixed this properly: https://github.com/horejsek/python-fastjsonschema/commit/2aee6eb286428cd97a456425e6aadff607f67d8e. Worth considering switching out the jsonschema implememtations?
Edited by Paul Tiplady