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

fix: (HttpClient) rate limit fix unlimited tries #171

Merged
merged 4 commits into from
Dec 18, 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
6 changes: 4 additions & 2 deletions airbyte_cdk/sources/streams/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _send_with_retry(
user_backoff_handler = user_defined_backoff_handler(max_tries=max_tries, max_time=max_time)(
self._send
)
rate_limit_backoff_handler = rate_limit_default_backoff_handler()
rate_limit_backoff_handler = rate_limit_default_backoff_handler(max_tries=max_tries)
backoff_handler = http_client_default_backoff_handler(
max_tries=max_tries, max_time=max_time
)
Expand Down Expand Up @@ -472,7 +472,9 @@ def _handle_error_resolution(

elif retry_endlessly:
raise RateLimitBackoffException(
request=request, response=response or exc, error_message=error_message
request=request,
response=(response if response is not None else exc),
error_message=error_message,
)

raise DefaultBackoffException(
Expand Down
7 changes: 5 additions & 2 deletions unit_tests/sources/streams/http/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from airbyte_cdk.sources.streams.http.exceptions import (
DefaultBackoffException,
RateLimitBackoffException,
RequestBodyException,
UserDefinedBackoffException,
)
Expand Down Expand Up @@ -690,10 +691,12 @@ def backoff_time(self, *args, **kwargs):

@pytest.mark.parametrize(
"exit_on_rate_limit, expected_call_count, expected_error",
[[True, 6, DefaultBackoffException], [False, 38, OverflowError]],
[[True, 6, DefaultBackoffException], [False, 6, RateLimitBackoffException]],
)
@pytest.mark.usefixtures("mock_sleep")
def test_backoff_strategy_endless(exit_on_rate_limit, expected_call_count, expected_error):
def test_backoff_strategy_endless(
exit_on_rate_limit: bool, expected_call_count: int, expected_error: Exception
):
http_client = HttpClient(
name="test", logger=MagicMock(), error_handler=HttpStatusErrorHandler(logger=MagicMock())
)
Expand Down
Loading