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 5 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
6 changes: 4 additions & 2 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 @@ -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() from resp.raise_for_status()

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
32 changes: 32 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,35 @@ 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.LOGGER.critical")
@mock.patch('tap_salesforce.salesforce.requests.Session.post')
def test_http_406_error_message(self, mocked_post, mocked_logger_critical, 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 "LOGGER.critical" is called once
self.assertEqual(mocked_logger_critical.call_count, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify if the retry count exceeds 1. Note that within the tap code, the maximum retry limit is configured to 10.