Skip to content

🎉 Python CDK: handle requests.exceptions.ChunkedEncodingError for broken connections #13260

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

Merged
merged 4 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

from .exceptions import DefaultBackoffException, UserDefinedBackoffException

TRANSIENT_EXCEPTIONS = (DefaultBackoffException, exceptions.ConnectTimeout, exceptions.ReadTimeout, exceptions.ConnectionError)
TRANSIENT_EXCEPTIONS = (
DefaultBackoffException,
exceptions.ConnectTimeout,
exceptions.ReadTimeout,
exceptions.ConnectionError,
exceptions.ChunkedEncodingError,
)

logger = logging.getLogger("airbyte")

Expand Down
2 changes: 1 addition & 1 deletion airbyte-cdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="airbyte-cdk",
version="0.1.59",
version="0.1.60",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
24 changes: 13 additions & 11 deletions airbyte-cdk/python/unit_tests/sources/streams/http/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,22 @@ def test_raise_on_http_errors_off_non_retryable_4xx(mocker, status_code):
assert response.status_code == status_code


def test_raise_on_http_errors_off_timeout(requests_mock):
stream = AutoFailFalseHttpStream()
requests_mock.register_uri("GET", stream.url_base, exc=requests.exceptions.ConnectTimeout)

with pytest.raises(requests.exceptions.ConnectTimeout):
list(stream.read_records(SyncMode.full_refresh))


def test_raise_on_http_errors_off_connection_error(requests_mock):
@pytest.mark.parametrize(
"error",
(
requests.exceptions.ConnectTimeout,
requests.exceptions.ConnectionError,
requests.exceptions.ChunkedEncodingError,
requests.exceptions.ReadTimeout
)
)
def test_raise_on_http_errors(mocker, error):
stream = AutoFailFalseHttpStream()
requests_mock.register_uri("GET", stream.url_base, exc=requests.exceptions.ConnectionError)
send_mock = mocker.patch.object(requests.Session, "send", side_effect=error())

with pytest.raises(requests.exceptions.ConnectionError):
with pytest.raises(error):
list(stream.read_records(SyncMode.full_refresh))
assert send_mock.call_count == stream.max_retries + 1


class PostHttpStream(StubBasicReadHttpStream):
Expand Down