Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit e1937d3

Browse files
committed
Handle invalid dates
It appears we don't always have valid dates and times on our source databases. With this small change we are trying to handle all invalid dates and hard-code them with the maximum supported date.
1 parent 388c633 commit e1937d3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

tap_postgres/sync_strategies/logical_replication.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,31 @@ def create_array_elem(elem, sql_datatype, conn_info):
145145
res = cur.fetchone()[0]
146146
return res
147147

148+
def parse_time(time):
149+
try:
150+
return parse(time).isoformat() + '+00:00'
151+
except:
152+
return "9999-12-31T00:00:00+00:00"
153+
148154
#pylint: disable=too-many-branches,too-many-nested-blocks
149155
def selected_value_to_singer_value_impl(elem, og_sql_datatype, conn_info):
150156
sql_datatype = og_sql_datatype.replace('[]', '')
151157

152158
if elem is None:
153159
return elem
154160
if sql_datatype == 'timestamp without time zone':
155-
return parse(elem).isoformat() + '+00:00'
161+
return parse_time(elem)
156162
if sql_datatype == 'timestamp with time zone':
157163
if isinstance(elem, datetime.datetime):
158164
return elem.isoformat()
159165

160-
return parse(elem).isoformat()
166+
return parse_time(elem)
161167
if sql_datatype == 'date':
162168
if isinstance(elem, datetime.date):
163169
#logical replication gives us dates as strings UNLESS they from an array
164170
return elem.isoformat() + 'T00:00:00+00:00'
165-
return parse(elem).isoformat() + "+00:00"
171+
172+
return parse_time(elem)
166173
if sql_datatype == 'time with time zone':
167174
return parse(elem).isoformat().split('T')[1]
168175
if sql_datatype == 'bit':

0 commit comments

Comments
 (0)