Skip to content

Commit

Permalink
HG-3499: parse empty strings as booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyyid committed Oct 9, 2024
1 parent 14a852a commit 3218765
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tap_hubspot_beta/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,33 @@ def stream_maps(self) -> List[StreamMap]:
)
]
return self._stream_maps


def process_row_types(self,row) -> Dict[str, Any]:
schema = self.schema['properties']
# If the row is null we ignore
if row is None:
return row

for field, value in row.items():
if field not in schema:
# Skip fields not found in the schema
continue

field_info = schema[field]
field_type = field_info.get("type", ["null"])[0]

if field_type == "boolean":
if value is None:
row[field] = False
elif not isinstance(value, bool):
# Attempt to cast to boolean
if value.lower() == "true":
row[field] = True
elif value == "" or value.lower() == "false":
row[field] = False

return row

def is_first_sync(self):
if self.stream_state.get("replication_key"):
return False
Expand Down
1 change: 1 addition & 0 deletions tap_hubspot_beta/client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ def post_process(self, row: dict, context: Optional[dict]) -> dict:
dt_field = datetime.fromtimestamp(int(row[field]) / 1000)
dt_field = dt_field.replace(tzinfo=None)
row[field] = dt_field.isoformat()
row = self.process_row_types(row)
return row
1 change: 1 addition & 0 deletions tap_hubspot_beta/client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def post_process(self, row: dict, context: Optional[dict]) -> dict:
row["updatedAt"] = row["hs_lastmodifieddate"]
row["createdAt"] = row["createdate"]
row["archived"] = False
row = self.process_row_types(row)
return row

def request_records(self, context: Optional[dict]) -> Iterable[dict]:
Expand Down
3 changes: 3 additions & 0 deletions tap_hubspot_beta/client_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def post_process(self, row: dict, context: Optional[dict]) -> dict:
del row["properties"]
# store archived value in _hg_archived
row["_hg_archived"] = False
row = self.process_row_types(row)
return row

def _sync_records( # noqa C901 # too complex
Expand Down Expand Up @@ -241,6 +242,7 @@ def post_process(self, row: dict, context: Optional[dict]) -> dict:
for name, value in row["properties"].items():
row[name] = value
del row["properties"]
row = self.process_row_types(row)
return row


Expand Down Expand Up @@ -296,6 +298,7 @@ def post_process(self, row: dict, context: Optional[dict]) -> dict:
for name, value in row["properties"].items():
row[name] = value
del row["properties"]
row = self.process_row_types(row)
return row

class hubspotHistoryV3Stream(hubspotV3Stream):
Expand Down

0 comments on commit 3218765

Please sign in to comment.