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

[TDL-25850] Add backoff for client error 406 #181

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions tap_salesforce/salesforce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from tap_salesforce.salesforce.rest import Rest
from tap_salesforce.salesforce.exceptions import (
TapSalesforceException,
TapSalesforceQuotaExceededException)
TapSalesforceQuotaExceededException,
Client406Error)

LOGGER = singer.get_logger()

Expand Down Expand Up @@ -278,8 +279,8 @@ def check_rest_quota_usage(self, headers):

# pylint: disable=too-many-arguments
@backoff.on_exception(backoff.expo,
(requests.exceptions.ConnectionError, requests.exceptions.Timeout),
max_tries=10,
(requests.exceptions.ConnectionError, requests.exceptions.Timeout, Client406Error),
max_tries=6,
factor=2,
on_backoff=log_backoff_attempt)
def _make_request(self, http_method, url, headers=None, body=None, stream=False, params=None):
Expand Down Expand Up @@ -307,7 +308,8 @@ def _make_request(self, http_method, url, headers=None, body=None, stream=False,
LOGGER.error('Took longer than %s seconds to hear from the server', request_timeout)
raise timeout_err


if resp.status_code == 406:
raise Client406Error

try:
resp.raise_for_status()
Expand Down
3 changes: 3 additions & 0 deletions tap_salesforce/salesforce/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class TapSalesforceQuotaExceededException(TapSalesforceException):

class TapSalesforceBulkAPIDisabledException(TapSalesforceException):
pass

class Client406Error(Exception):
pass
3 changes: 2 additions & 1 deletion tests/test_salesforce_all_fields_non_custom_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def streams_to_selected_fields(self):
return non_custom_fields

def test_non_custom_fields(self):
excluded_fields = {'MlFeatureValueMetric'}
for stream in self.streams_to_test():
with self.subTest(stream=stream):
expected_non_custom_fields = self.selected_fields.get(stream,set())
expected_non_custom_fields = self.selected_fields.get(stream,set()) - excluded_fields
replicated_non_custom_fields = self.actual_fields.get(stream, set())
#Verify at least one non-custom field is replicated
self.assertGreater(len(replicated_non_custom_fields),0,
Expand Down
31 changes: 31 additions & 0 deletions tests/unittests/test_multiline_critical_error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,34 @@ def test_multiline_critical_error_message(self, mocked_main_impl, mocked_logger_

# verify "LOGGER.critical" is called 5 times, as the error raised contains 5 lines
self.assertEqual(mocked_logger_critical.call_count, 5)

@mock.patch("tap_salesforce.singer_utils.parse_args")
@mock.patch('tap_salesforce.salesforce.requests.Session.post')
def test_http_406_error_message(self, mocked_post, mocked_parse_args):

args = mock.MagicMock()
args.config = {
"refresh_token": "abc",
"client_id": "abc",
"client_secret": "abc",
"quota_percent_total": 10.1,
"quota_percent_per_run": 10.1,
"is_sandbox": True,
"start_date": "2020-02-04T07:46:29Z",
"api_type": "abc",
"lookback_window": "12"
}
mocked_parse_args.return_value = args

# Define the mock response
mock_response = mock.MagicMock()
mock_response.status_code = 406
mocked_post.return_value = mock_response


# verify "Exception" is raise on function call
with self.assertRaises(Exception):
main()

# verify "requests.Session.post" is called 6 times
self.assertEqual(mocked_post.call_count, 6)