Skip to content

Commit

Permalink
FIX: Hack deserialisation of event attributes from bigquery to correc…
Browse files Browse the repository at this point in the history
…t types
  • Loading branch information
thclark committed Jun 11, 2024
1 parent dc6bf36 commit 30de609
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions octue/cloud/pub_sub/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,22 @@ def _unflatten_events(events):
for event in events:
event["event"]["kind"] = event.pop("kind")

# Deal with null as a string
parent_question_uuid = event.pop("parent_question_uuid")
parent_question_uuid = None if parent_question_uuid == "null" else parent_question_uuid

# Deal with converison of string attributes back to bool and int
other_attributes = event.pop("other_attributes")
if "forward_logs" in other_attributes:
other_attributes['forward_logs'] = other_attributes.pop("forward_logs") == "1"

if "retry_count" in other_attributes:
other_attributes['retry_count'] = int(other_attributes.pop("retry_count"))


event["attributes"] = {
"originator_question_uuid": event.pop("originator_question_uuid"),
"parent_question_uuid": event.pop("parent_question_uuid"),
"parent_question_uuid": parent_question_uuid,
"question_uuid": event.pop("question_uuid"),
"datetime": event.pop("datetime").isoformat(),
"uuid": event.pop("uuid"),
Expand All @@ -174,7 +187,8 @@ def _unflatten_events(events):
"sender_sdk_version": event.pop("sender_sdk_version"),
"recipient": event.pop("recipient"),
"order": event.pop("order"),
**event.pop("other_attributes"),
**other_attributes
}


return events

0 comments on commit 30de609

Please sign in to comment.