Skip to content

Commit

Permalink
add read only fields to memory, clean record
Browse files Browse the repository at this point in the history
  • Loading branch information
keyn4 committed Sep 10, 2024
1 parent bfac06a commit 9be2c50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions target_salesforce_v3/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@ def preprocess_record(self, record, context):
for key in record:
if isinstance(record.get(key), datetime):
record[key] = record[key].isoformat()

# clean any read only fields
for field in self._target.read_only_fields.get(self.stream_name, []):
record.pop(field, None)
return record

def upsert_record(self, record, context):
Expand Down Expand Up @@ -1010,6 +1014,12 @@ def upsert_record(self, record, context):
if "INVALID_FIELD_FOR_INSERT_UPDATE" in str(e):
fields = json.loads(str(e))[0]['fields']
self.logger.warning(f"Attempted to write read-only fields: {fields}. Removing them and retrying.")
# append read-only field to a list
if not self._target.read_only_fields.get(self.stream_name):
self._target.read_only_fields[self.stream_name] = fields
else:
self._target.read_only_fields[self.stream_name].extend(fields)
# remove read-only fields from record
for f in fields:
record.pop(f, None)
# retry
Expand Down
2 changes: 2 additions & 0 deletions target_salesforce_v3/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class TargetSalesforceV3(TargetHotglue):
name = "target-salesforce-v3"
MAX_PARALLELISM = 10
SINK_TYPES = SINK_TYPES
read_only_fields = {}

def get_sink_class(self, stream_name: str):
"""Get sink for a stream."""
for sink_class in SINK_TYPES:
Expand Down

0 comments on commit 9be2c50

Please sign in to comment.