Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add read only fields to memory, clean record #23

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion 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 @@ -1008,8 +1012,17 @@ 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] = []
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
Loading