Skip to content
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
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changes
-------

3.0.0 (2025-11-30)
^^^^^^^^^^^^^^^^^^^
* BREAKING: forbid creating loose ``ClientSession`` when ``AioBaseClient`` exits context

2.26.0 (2025-11-27)
^^^^^^^^^^^^^^^^^^^
* bump botocore dependency specification
Expand Down
2 changes: 1 addition & 1 deletion aiobotocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.26.0'
__version__ = '3.0.0'
10 changes: 8 additions & 2 deletions aiobotocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def __init__(

# TODO: handle socket_options
# keep track of sessions by proxy url (if any)
self._sessions: dict[Optional[str], aiohttp.ClientSession] = {}
self._sessions: Optional[
dict[Optional[str], aiohttp.ClientSession]
] = None
self._verify = verify
self._proxy_config = ProxyConfiguration(
proxies=proxies, proxies_settings=proxies_config
Expand Down Expand Up @@ -100,13 +102,17 @@ def __init__(
# request so don't need proxy manager

async def __aenter__(self):
assert not self._sessions
assert self._sessions is None
self._sessions = {}

return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
assert self._sessions is not None, 'Session was never entered'
self._sessions.clear()
await self._exit_stack.aclose()
# Make _sessions unusable once context is exited
self._sessions = None

def _get_ssl_context(self):
return create_urllib3_context()
Expand Down
20 changes: 20 additions & 0 deletions tests/test_httpsession.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import botocore
import pytest


async def test_cannot_create_client_sessions_outside_context(session):
s3_client_context = session.create_client(
's3',
'us-west-2',
aws_secret_access_key="xxx",
aws_access_key_id="xxx",
)

async with s3_client_context as s3_client:
pass

with pytest.raises(
botocore.exceptions.HTTPClientError,
match="'NoneType' object has no attribute 'get'",
):
await s3_client.list_buckets()
Loading