From 65f2a3e7b9e47bf6b2756441096144b6152cecbc Mon Sep 17 00:00:00 2001 From: Peter Kosztolanyi Date: Sun, 14 Oct 2018 00:52:31 +0100 Subject: [PATCH 1/2] Fixed multipleOf validation issue: convert float to Decimal --- target_postgres/__init__.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/target_postgres/__init__.py b/target_postgres/__init__.py index 15a12b8..3dd408d 100644 --- a/target_postgres/__init__.py +++ b/target_postgres/__init__.py @@ -13,13 +13,24 @@ from tempfile import TemporaryFile import pkg_resources -from jsonschema.validators import Draft4Validator +from jsonschema.validators import Draft4Validator, FormatChecker import singer from target_postgres.db_sync import DbSync logger = singer.get_logger() +def float_to_decimal(value): + '''Walk the given data structure and turn all instances of float into + double.''' + if isinstance(value, float): + return Decimal(str(value)) + if isinstance(value, list): + return [float_to_decimal(child) for child in value] + if isinstance(value, dict): + return {k: float_to_decimal(v) for k, v in value.items()} + return value + def emit_state(state): if state is not None: line = json.dumps(state) @@ -65,7 +76,7 @@ def persist_lines(config, lines): stream = o['stream'] # Validate record - validators[stream].validate(o['record']) + validators[stream].validate(float_to_decimal(o['record'])) sync = stream_to_sync[stream] @@ -93,7 +104,8 @@ def persist_lines(config, lines): raise Exception("Line is missing required key 'stream': {}".format(line)) stream = o['stream'] schemas[stream] = o - validators[stream] = Draft4Validator(o['schema']) + schema = float_to_decimal(o['schema']) + validators[stream] = Draft4Validator(schema, format_checker=FormatChecker()) if 'key_properties' not in o: raise Exception("key_properties field is required") key_properties[stream] = o['key_properties'] From 6288bc8b65c11fd6e2956e7e563fccc5cda0e193 Mon Sep 17 00:00:00 2001 From: Peter Kosztolanyi Date: Tue, 23 Oct 2018 22:28:03 +0100 Subject: [PATCH 2/2] Import required modules --- target_postgres/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target_postgres/__init__.py b/target_postgres/__init__.py index 3dd408d..fd010ee 100644 --- a/target_postgres/__init__.py +++ b/target_postgres/__init__.py @@ -13,7 +13,8 @@ from tempfile import TemporaryFile import pkg_resources -from jsonschema.validators import Draft4Validator, FormatChecker +from jsonschema import Draft4Validator, FormatChecker +from decimal import Decimal import singer from target_postgres.db_sync import DbSync