From fb4a266df07bca52426687a7e0cd75b83903f14b Mon Sep 17 00:00:00 2001 From: Kevin James Date: Sat, 6 Apr 2024 13:43:54 +0100 Subject: [PATCH] fix(auth): fixup aiohttp v3.3.0 compat Avoid new API usage, introduce ability to avoid stomping over configured session-level `auto_decompress` setting. --- auth/gcloud/aio/auth/session.py | 20 +++++++++++++++----- auth/poetry.lock | 2 +- auth/pyproject.rest.toml | 2 +- auth/pyproject.toml | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/auth/gcloud/aio/auth/session.py b/auth/gcloud/aio/auth/session.py index 2cb621b07..62d4a3c34 100644 --- a/auth/gcloud/aio/auth/session.py +++ b/auth/gcloud/aio/auth/session.py @@ -55,7 +55,7 @@ async def get( self, url: str, headers: Optional[Mapping[str, str]], timeout: float, params: Optional[Mapping[str, Union[int, str]]], stream: bool, - auto_decompress: bool, + auto_decompress: Optional[bool], ) -> Response: pass @@ -200,7 +200,7 @@ async def get( # type: ignore[override] timeout: Timeout = 10, params: Optional[Mapping[str, Union[int, str]]] = None, stream: Optional[bool] = None, - auto_decompress: bool = True, + auto_decompress: Optional[bool] = None, ) -> aiohttp.ClientResponse: if not isinstance(timeout, aiohttp.ClientTimeout): timeout = aiohttp.ClientTimeout(total=timeout) @@ -211,11 +211,21 @@ async def get( # type: ignore[override] 'this argument is only used by SyncSession', stream, ) + + # TODO: in aiohttp v3.9.0, session.get(..) learned the + # auto_decompress argument. Once our minimum bound is >=3.9.0, + # update this block to avoid patching the prviate session + # attribute. + # pylint: disable=protected-access + orig = self.session._auto_decompress + if auto_decompress is not None: + self.session._auto_decompress = auto_decompress resp = await self.session.get( url, headers=headers, timeout=timeout, params=params, - auto_decompress=auto_decompress, ) + self.session._auto_decompress = orig + await _raise_for_status(resp) return resp @@ -339,9 +349,9 @@ async def get( timeout: float = 10, params: Optional[Mapping[str, Union[int, str]]] = None, stream: bool = False, - auto_decompress: bool = True, + auto_decompress: Optional[bool] = None, ) -> Response: - if not auto_decompress and not stream: + if auto_decompress is False and not stream: warnings.warn( 'the requests library always decompresses responses when ' 'outside of streaming mode; when auto_decompress is ' diff --git a/auth/poetry.lock b/auth/poetry.lock index 7e782b927..fe64a1508 100644 --- a/auth/poetry.lock +++ b/auth/poetry.lock @@ -740,4 +740,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">= 3.8, < 4.0" -content-hash = "e295b88139ec01ee3308b84a919b8a168da97f3f49c00b5d0de73f6c775fbac8" +content-hash = "4f4af4637004135c241d86fffa25a8f11f6e2c10f00a42103d646babda58e806" diff --git a/auth/pyproject.rest.toml b/auth/pyproject.rest.toml index 7a5c34698..bfba30f76 100644 --- a/auth/pyproject.rest.toml +++ b/auth/pyproject.rest.toml @@ -21,7 +21,7 @@ classifiers = [ [tool.poetry.dependencies] python = ">= 3.8, < 4.0" -# aiohttp = ">= 3.9.0, < 4.0.0" +# aiohttp = ">= 3.3.0, < 4.0.0" backoff = ">= 1.0.0, < 3.0.0" chardet = ">= 2.0, < 6.0" # See https://cryptography.io/en/latest/api-stability/#deprecation diff --git a/auth/pyproject.toml b/auth/pyproject.toml index 9d5b50994..bef74b7d7 100644 --- a/auth/pyproject.toml +++ b/auth/pyproject.toml @@ -21,7 +21,7 @@ classifiers = [ [tool.poetry.dependencies] python = ">= 3.8, < 4.0" -aiohttp = ">= 3.9.0, < 4.0.0" +aiohttp = ">= 3.3.0, < 4.0.0" backoff = ">= 1.0.0, < 3.0.0" chardet = ">= 2.0, < 6.0" # See https://cryptography.io/en/latest/api-stability/#deprecation