Skip to content

Commit

Permalink
add backwards compatibility (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
thehesiod authored Aug 25, 2021
1 parent ef96004 commit 2a358e1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changes
-------
1.4.1 (2021-08-24)
^^^^^^^^^^^^^^^^^^
* put backwards incompatible changes behind ``AIOBOTOCORE_DEPRECATED_1_4_0_APIS`` env var. This means that `#876 <https://github.com/aio-libs/aiobotocore/issues/876>`_ will not work unless this env var has been set to 0.

1.4.0 (2021-08-20)
^^^^^^^^^^^^^^^^^^
* fix retries via config `#877 <https://github.com/aio-libs/aiobotocore/pull/877>`_
Expand Down
16 changes: 15 additions & 1 deletion aiobotocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
__version__ = '1.4.0'
# NOTE: These imports are deprecated and will be removed in 2.x
import os

# Enabling this will enable the old http exception behavior that exposed raw aiohttp
# exceptions and old session variables available via __init__. Disabling will swap to
# botocore exceptions and will not have these imports to match botocore.
# NOTE: without setting this to 0, retries may not work, see #876
DEPRECATED_1_4_0_APIS = int(os.getenv('AIOBOTOCORE_DEPRECATED_1_4_0_APIS', '1'))

if DEPRECATED_1_4_0_APIS:
from .session import get_session, AioSession

__all__ = ['get_session', 'AioSession']

__version__ = '1.4.1'
22 changes: 22 additions & 0 deletions aiobotocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
EndpointConnectionError, ProxyConnectionError, ConnectTimeoutError, \
ConnectionClosedError, HTTPClientError, ReadTimeoutError, logger, get_cert_path

from aiobotocore import DEPRECATED_1_4_0_APIS
from aiobotocore._endpoint_helpers import _text, _IOBaseWrapper, \
ClientResponseProxy

Expand Down Expand Up @@ -162,22 +163,43 @@ async def send(self, request):

return resp
except ClientSSLError as e:
if DEPRECATED_1_4_0_APIS:
raise

raise SSLError(endpoint_url=request.url, error=e)
except (ClientConnectorError, socket.gaierror) as e:
if DEPRECATED_1_4_0_APIS:
raise

raise EndpointConnectionError(endpoint_url=request.url, error=e)
except (ClientProxyConnectionError, ClientHttpProxyError) as e:
if DEPRECATED_1_4_0_APIS:
raise

raise ProxyConnectionError(proxy_url=proxy_url, error=e)
except ServerTimeoutError as e:
if DEPRECATED_1_4_0_APIS:
raise

raise ConnectTimeoutError(endpoint_url=request.url, error=e)
except asyncio.TimeoutError as e:
if DEPRECATED_1_4_0_APIS:
raise

raise ReadTimeoutError(endpoint_url=request.url, error=e)
except ServerDisconnectedError as e:
if DEPRECATED_1_4_0_APIS:
raise

raise ConnectionClosedError(
error=e,
request=request,
endpoint_url=request.url
)
except Exception as e:
if DEPRECATED_1_4_0_APIS:
raise

message = 'Exception received when sending urllib3 HTTP request'
logger.debug(message, exc_info=True)
raise HTTPClientError(error=e)
11 changes: 8 additions & 3 deletions tests/test_basic_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import pytest
import aioitertools
from botocore.exceptions import EndpointConnectionError

from aiobotocore import httpsession


async def fetch_all(pages):
Expand All @@ -26,10 +27,14 @@ async def test_can_make_request(s3_client):

@pytest.mark.moto
@pytest.mark.asyncio
async def test_fail_proxy_request(aa_fail_proxy_config, s3_client):
async def test_fail_proxy_request(aa_fail_proxy_config, s3_client, monkeypatch):
# based on test_can_make_request

with pytest.raises(EndpointConnectionError):
with pytest.raises(httpsession.ClientProxyConnectionError):
await s3_client.list_buckets()

monkeypatch.setattr(httpsession, 'DEPRECATED_1_4_0_APIS', 0)
with pytest.raises(httpsession.EndpointConnectionError):
await s3_client.list_buckets()


Expand Down
9 changes: 6 additions & 3 deletions tests/test_session.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging

import pytest
from botocore.exceptions import EndpointConnectionError
from _pytest.logging import LogCaptureFixture

from aiobotocore.session import AioSession
from aiobotocore.config import AioConfig
from aiobotocore import httpsession


@pytest.mark.moto
Expand All @@ -24,7 +25,7 @@ def handler(**kwargs):

@pytest.mark.moto
@pytest.mark.asyncio
async def test_retry(session: AioSession, caplog):
async def test_retry(session: AioSession, caplog: LogCaptureFixture, monkeypatch):
caplog.set_level(logging.DEBUG)

config = AioConfig(
Expand All @@ -42,7 +43,9 @@ async def test_retry(session: AioSession, caplog):
's3', config=config, aws_secret_access_key="xxx", aws_access_key_id="xxx",
endpoint_url='http://localhost:7878') as client:

with pytest.raises(EndpointConnectionError):
# this needs the new style exceptions to work
monkeypatch.setattr(httpsession, 'DEPRECATED_1_4_0_APIS', 0)
with pytest.raises(httpsession.EndpointConnectionError):
await client.get_object(Bucket='foo', Key='bar')

assert 'sleeping for' in caplog.text

0 comments on commit 2a358e1

Please sign in to comment.