Skip to content

Commit 2a358e1

Browse files
authored
add backwards compatibility (#881)
1 parent ef96004 commit 2a358e1

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

CHANGES.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changes
22
-------
3+
1.4.1 (2021-08-24)
4+
^^^^^^^^^^^^^^^^^^
5+
* 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.
6+
37
1.4.0 (2021-08-20)
48
^^^^^^^^^^^^^^^^^^
59
* fix retries via config `#877 <https://github.com/aio-libs/aiobotocore/pull/877>`_

aiobotocore/__init__.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
__version__ = '1.4.0'
1+
# NOTE: These imports are deprecated and will be removed in 2.x
2+
import os
3+
4+
# Enabling this will enable the old http exception behavior that exposed raw aiohttp
5+
# exceptions and old session variables available via __init__. Disabling will swap to
6+
# botocore exceptions and will not have these imports to match botocore.
7+
# NOTE: without setting this to 0, retries may not work, see #876
8+
DEPRECATED_1_4_0_APIS = int(os.getenv('AIOBOTOCORE_DEPRECATED_1_4_0_APIS', '1'))
9+
10+
if DEPRECATED_1_4_0_APIS:
11+
from .session import get_session, AioSession
12+
13+
__all__ = ['get_session', 'AioSession']
14+
15+
__version__ = '1.4.1'

aiobotocore/httpsession.py

+22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
EndpointConnectionError, ProxyConnectionError, ConnectTimeoutError, \
1515
ConnectionClosedError, HTTPClientError, ReadTimeoutError, logger, get_cert_path
1616

17+
from aiobotocore import DEPRECATED_1_4_0_APIS
1718
from aiobotocore._endpoint_helpers import _text, _IOBaseWrapper, \
1819
ClientResponseProxy
1920

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

163164
return resp
164165
except ClientSSLError as e:
166+
if DEPRECATED_1_4_0_APIS:
167+
raise
168+
165169
raise SSLError(endpoint_url=request.url, error=e)
166170
except (ClientConnectorError, socket.gaierror) as e:
171+
if DEPRECATED_1_4_0_APIS:
172+
raise
173+
167174
raise EndpointConnectionError(endpoint_url=request.url, error=e)
168175
except (ClientProxyConnectionError, ClientHttpProxyError) as e:
176+
if DEPRECATED_1_4_0_APIS:
177+
raise
178+
169179
raise ProxyConnectionError(proxy_url=proxy_url, error=e)
170180
except ServerTimeoutError as e:
181+
if DEPRECATED_1_4_0_APIS:
182+
raise
183+
171184
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
172185
except asyncio.TimeoutError as e:
186+
if DEPRECATED_1_4_0_APIS:
187+
raise
188+
173189
raise ReadTimeoutError(endpoint_url=request.url, error=e)
174190
except ServerDisconnectedError as e:
191+
if DEPRECATED_1_4_0_APIS:
192+
raise
193+
175194
raise ConnectionClosedError(
176195
error=e,
177196
request=request,
178197
endpoint_url=request.url
179198
)
180199
except Exception as e:
200+
if DEPRECATED_1_4_0_APIS:
201+
raise
202+
181203
message = 'Exception received when sending urllib3 HTTP request'
182204
logger.debug(message, exc_info=True)
183205
raise HTTPClientError(error=e)

tests/test_basic_s3.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import pytest
55
import aioitertools
6-
from botocore.exceptions import EndpointConnectionError
6+
7+
from aiobotocore import httpsession
78

89

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

2728
@pytest.mark.moto
2829
@pytest.mark.asyncio
29-
async def test_fail_proxy_request(aa_fail_proxy_config, s3_client):
30+
async def test_fail_proxy_request(aa_fail_proxy_config, s3_client, monkeypatch):
3031
# based on test_can_make_request
3132

32-
with pytest.raises(EndpointConnectionError):
33+
with pytest.raises(httpsession.ClientProxyConnectionError):
34+
await s3_client.list_buckets()
35+
36+
monkeypatch.setattr(httpsession, 'DEPRECATED_1_4_0_APIS', 0)
37+
with pytest.raises(httpsession.EndpointConnectionError):
3338
await s3_client.list_buckets()
3439

3540

tests/test_session.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import logging
22

33
import pytest
4-
from botocore.exceptions import EndpointConnectionError
4+
from _pytest.logging import LogCaptureFixture
55

66
from aiobotocore.session import AioSession
77
from aiobotocore.config import AioConfig
8+
from aiobotocore import httpsession
89

910

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

2526
@pytest.mark.moto
2627
@pytest.mark.asyncio
27-
async def test_retry(session: AioSession, caplog):
28+
async def test_retry(session: AioSession, caplog: LogCaptureFixture, monkeypatch):
2829
caplog.set_level(logging.DEBUG)
2930

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

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

4851
assert 'sleeping for' in caplog.text

0 commit comments

Comments
 (0)