Skip to content

Commit

Permalink
fix(auth): fixup aiohttp v3.3.0 compat
Browse files Browse the repository at this point in the history
Avoid new API usage, introduce ability to avoid stomping over configured
session-level `auto_decompress` setting.
  • Loading branch information
TheKevJames committed Apr 6, 2024
1 parent e331973 commit fb4a266
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
20 changes: 15 additions & 5 deletions auth/gcloud/aio/auth/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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 '
Expand Down
2 changes: 1 addition & 1 deletion auth/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth/pyproject.rest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion auth/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb4a266

Please sign in to comment.