Skip to content

Commit

Permalink
fix report discover
Browse files Browse the repository at this point in the history
  • Loading branch information
sehnem committed Jan 30, 2023
1 parent 9b05e22 commit a017462
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions tap_salesforce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import singer.utils as singer_utils
from singer import metadata, metrics
import tap_salesforce.salesforce
from requests.exceptions import RequestException
from requests.exceptions import RequestException, HTTPError
from tap_salesforce.sync import (sync_stream, resume_syncing_bulk_query, get_stream_version, ACTIVITY_STREAMS)
from tap_salesforce.salesforce import Salesforce
from tap_salesforce.salesforce.bulk import Bulk
Expand Down Expand Up @@ -217,7 +217,11 @@ def get_reports_list(sf):
url = sf.data_url.format(sf.instance_url, endpoint)

while not done:
response = sf._make_request('GET', url, headers=headers, params=params)
try:
response = sf._make_request('GET', url, headers=headers, params=params)
except HTTPError as e:
LOGGER.warning("Reports not supported.")
return output
response_json = response.json()
done = response_json.get("done")
output.extend(response_json.get("records", []))
Expand Down Expand Up @@ -348,34 +352,35 @@ def do_discover(sf):
mdata = metadata.new()
properties = {}

for report in reports:
field_name = f"Report_{report['DeveloperName']}"
properties[field_name] = dict(type=["null", "object", "string"])
mdata = metadata.write(
mdata, ('properties', field_name), 'selected-by-default', False)

mdata = metadata.write(
mdata,
(),
'forced-replication-method',
{'replication-method': 'FULL_TABLE'})

mdata = metadata.write(mdata, (), 'table-key-properties', [])

schema = {
'type': 'object',
'additionalProperties': False,
'properties': properties
}
if reports:
for report in reports:
field_name = f"Report_{report['DeveloperName']}"
properties[field_name] = dict(type=["null", "object", "string"])
mdata = metadata.write(
mdata, ('properties', field_name), 'selected-by-default', False)

entry = {
'stream': "ReportList",
'tap_stream_id': "ReportList",
'schema': schema,
'metadata': metadata.to_list(mdata)
}

entries.append(entry)
mdata = metadata.write(
mdata,
(),
'forced-replication-method',
{'replication-method': 'FULL_TABLE'})

mdata = metadata.write(mdata, (), 'table-key-properties', [])

schema = {
'type': 'object',
'additionalProperties': False,
'properties': properties
}

entry = {
'stream': "ReportList",
'tap_stream_id': "ReportList",
'schema': schema,
'metadata': metadata.to_list(mdata)
}

entries.append(entry)

# For each custom setting field, remove its associated tag from entries
# See Blacklisting.md for more information
Expand Down

0 comments on commit a017462

Please sign in to comment.