Skip to content

Commit 4759654

Browse files
authored
fix: (HttpClient) rate limit fix unlimited tries (#171)
Signed-off-by: Artem Inzhyyants <[email protected]>
1 parent adef1e8 commit 4759654

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

airbyte_cdk/sources/streams/http/http_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def _send_with_retry(
262262
user_backoff_handler = user_defined_backoff_handler(max_tries=max_tries, max_time=max_time)(
263263
self._send
264264
)
265-
rate_limit_backoff_handler = rate_limit_default_backoff_handler()
265+
rate_limit_backoff_handler = rate_limit_default_backoff_handler(max_tries=max_tries)
266266
backoff_handler = http_client_default_backoff_handler(
267267
max_tries=max_tries, max_time=max_time
268268
)
@@ -472,7 +472,9 @@ def _handle_error_resolution(
472472

473473
elif retry_endlessly:
474474
raise RateLimitBackoffException(
475-
request=request, response=response or exc, error_message=error_message
475+
request=request,
476+
response=(response if response is not None else exc),
477+
error_message=error_message,
476478
)
477479

478480
raise DefaultBackoffException(

unit_tests/sources/streams/http/test_http_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from airbyte_cdk.sources.streams.http.exceptions import (
2222
DefaultBackoffException,
23+
RateLimitBackoffException,
2324
RequestBodyException,
2425
UserDefinedBackoffException,
2526
)
@@ -690,10 +691,12 @@ def backoff_time(self, *args, **kwargs):
690691

691692
@pytest.mark.parametrize(
692693
"exit_on_rate_limit, expected_call_count, expected_error",
693-
[[True, 6, DefaultBackoffException], [False, 38, OverflowError]],
694+
[[True, 6, DefaultBackoffException], [False, 6, RateLimitBackoffException]],
694695
)
695696
@pytest.mark.usefixtures("mock_sleep")
696-
def test_backoff_strategy_endless(exit_on_rate_limit, expected_call_count, expected_error):
697+
def test_backoff_strategy_endless(
698+
exit_on_rate_limit: bool, expected_call_count: int, expected_error: Exception
699+
):
697700
http_client = HttpClient(
698701
name="test", logger=MagicMock(), error_handler=HttpStatusErrorHandler(logger=MagicMock())
699702
)

0 commit comments

Comments
 (0)