Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bump logic to extract read-only fields
Browse files Browse the repository at this point in the history
keyn4 committed Sep 12, 2024
1 parent 9be2c50 commit 1b96ab8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions target_salesforce_v3/sinks.py
Original file line number Diff line number Diff line change
@@ -1012,13 +1012,16 @@ def upsert_record(self, record, context):
return id, True, state_updates
except Exception as e:
if "INVALID_FIELD_FOR_INSERT_UPDATE" in str(e):
fields = json.loads(str(e))[0]['fields']
try:
fields = json.loads(str(e))[0]['fields']
except:
raise Exception(f"Attempted to write read-only fields. Unable to extract read-only fields to retry request: {str(e)}")

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)
self._target.read_only_fields[self.stream_name] = []
self._target.read_only_fields[self.stream_name].extend(fields)
# remove read-only fields from record
for f in fields:
record.pop(f, None)

0 comments on commit 1b96ab8

Please sign in to comment.