Skip to content

Commit

Permalink
cdk: remove false error logging in _send (#11650)
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere authored Apr 4, 2022
1 parent afc1976 commit 2d27774
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions airbyte-cdk/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.53
Remove a false positive error logging during the send process.

## 0.1.52
Fix BaseBackoffException constructor

Expand Down
9 changes: 6 additions & 3 deletions airbyte-cdk/python/airbyte_cdk/sources/streams/http/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
from abc import ABC, abstractmethod
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Union
from urllib.error import HTTPError
from urllib.parse import urljoin

import requests
Expand Down Expand Up @@ -294,9 +295,11 @@ def _send(self, request: requests.PreparedRequest, request_kwargs: Mapping[str,
raise DefaultBackoffException(request=request, response=response)
elif self.raise_on_http_errors:
# Raise any HTTP exceptions that happened in case there were unexpected ones
self.logger.error(f"Request raised an error with response: {response.text}")
response.raise_for_status()

try:
response.raise_for_status()
except HTTPError as exc:
self.logger.error(response.text)
raise exc
return response

def _send_request(self, request: requests.PreparedRequest, request_kwargs: Mapping[str, Any]) -> requests.Response:
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.52",
version="0.1.53",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
18 changes: 18 additions & 0 deletions airbyte-cdk/python/unit_tests/sources/streams/http/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,21 @@ def test_using_cache(mocker):
pass

assert parent_stream.cassete.play_count != 0


class AutoFailTrueHttpStream(StubBasicReadHttpStream):
raise_on_http_errors = True


@pytest.mark.parametrize("status_code", range(400, 600))
def test_send_raise_on_http_errors_logs(mocker, status_code):
mocker.patch.object(AutoFailTrueHttpStream, "logger")
mocker.patch.object(AutoFailTrueHttpStream, "should_retry", mocker.Mock(return_value=False))
stream = AutoFailTrueHttpStream()
req = requests.Response()
req.status_code = status_code
mocker.patch.object(requests.Session, "send", return_value=req)
with pytest.raises(requests.exceptions.HTTPError):
response = stream._send_request(req, {})
stream.logger.error.assert_called_with(response.text)
assert response.status_code == status_code

0 comments on commit 2d27774

Please sign in to comment.