diff --git a/src/aleph/sdk/client/authenticated_http.py b/src/aleph/sdk/client/authenticated_http.py index cb2f3e01..f84b97ca 100644 --- a/src/aleph/sdk/client/authenticated_http.py +++ b/src/aleph/sdk/client/authenticated_http.py @@ -89,9 +89,6 @@ def __init__( ) self.account = account - async def __aenter__(self) -> "AuthenticatedAlephHttpClient": - return self - async def ipfs_push(self, content: Mapping) -> str: """ Push arbitrary content as JSON to the IPFS service. diff --git a/src/aleph/sdk/client/http.py b/src/aleph/sdk/client/http.py index 8f3b7f90..9dfb588a 100644 --- a/src/aleph/sdk/client/http.py +++ b/src/aleph/sdk/client/http.py @@ -68,12 +68,12 @@ def http_session(self) -> aiohttp.ClientSession: raise Exception( f"{self.__class__.__name__} can only be using within an async context manager.\n\n" "Please use it this way:\n\n" - " async with {self.__class__.__name__}(...) as client:" + f" async with {self.__class__.__name__}(...) as client:" ) return self._http_session - async def __aenter__(self) -> "AlephHttpClient": + async def __aenter__(self): if self._http_session is None: self._http_session = ( aiohttp.ClientSession( @@ -95,7 +95,9 @@ async def __aenter__(self) -> "AlephHttpClient": return self async def __aexit__(self, exc_type, exc_val, exc_tb): - await self.http_session.close() + # Avoid cascade in error handling + if self._http_session is not None: + await self._http_session.close() async def fetch_aggregate(self, address: str, key: str) -> Dict[str, Dict]: params: Dict[str, Any] = {"keys": key}