From fccfc4f6934362513526bc06dbc731334d966d95 Mon Sep 17 00:00:00 2001 From: Yordan Ivanov Date: Wed, 4 Nov 2020 17:31:51 +0200 Subject: [PATCH] Parse invalid dates Python can only parse dates up to 9999-12-31. When we try to work with a date past the maximum supported, a ValueError is being thrown. These dates are invalid anyway, so I decided to just hardcode them to the maximum supported date. --- tap_postgres/sync_strategies/logical_replication.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tap_postgres/sync_strategies/logical_replication.py b/tap_postgres/sync_strategies/logical_replication.py index acacb98..84f2e78 100644 --- a/tap_postgres/sync_strategies/logical_replication.py +++ b/tap_postgres/sync_strategies/logical_replication.py @@ -158,7 +158,10 @@ def selected_value_to_singer_value_impl(elem, og_sql_datatype, conn_info): if isinstance(elem, datetime.date): #logical replication gives us dates as strings UNLESS they from an array return elem.isoformat() + 'T00:00:00+00:00' - return parse(elem).isoformat() + "+00:00" + try: + return parse(elem).isoformat() + "+00:00" + except ValueError: + return parse('9999-12-31T00:00:00+00:00').isoformat() if sql_datatype == 'time with time zone': return parse(elem).isoformat().split('T')[1] if sql_datatype == 'bit':