Skip to content

Comments

feat: Support timeout as aiohttp.ClientTimeout and total_attempts (max retries) in AsyncAuthorizedSession#1961

Merged
agrawalradhika-cell merged 14 commits intogoogleapis:mainfrom
yinghsienwu:timeout
Feb 20, 2026
Merged

feat: Support timeout as aiohttp.ClientTimeout and total_attempts (max retries) in AsyncAuthorizedSession#1961
agrawalradhika-cell merged 14 commits intogoogleapis:mainfrom
yinghsienwu:timeout

Conversation

@yinghsienwu
Copy link
Contributor

@yinghsienwu yinghsienwu commented Feb 18, 2026

b/485304839

@yinghsienwu yinghsienwu requested review from a team as code owners February 18, 2026 18:09
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yinghsienwu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the AsyncAuthorizedSession by providing more flexible control over network request behavior. It introduces the ability to pass aiohttp.ClientTimeout objects directly for fine-grained timeout configuration and adds a total_attempts parameter to manage the maximum number of retries for a given request. These changes improve the robustness and configurability of asynchronous HTTP operations.

Highlights

  • Aiohttp ClientTimeout Support: The timeout parameter in AsyncAuthorizedSession and its request methods now accepts an aiohttp.ClientTimeout object, allowing for more granular control over request timeouts beyond a simple float value.
  • Configurable Total Retries: A new total_attempts parameter has been introduced to the request method, enabling users to specify the maximum number of retry attempts for a given request, enhancing control over retry logic.
Changelog
  • google/auth/aio/transport/aiohttp.py
    • Added typing.Any, typing.Union, and typing imports to support flexible type hints.
    • Implemented conditional import and type checking for aiohttp.ClientTimeout to ensure compatibility.
    • Modified the timeout parameter in the __call__ method to accept Union[float, ClientTimeout].
    • Updated the internal timeout handling logic to directly use an aiohttp.ClientTimeout object if provided.
  • google/auth/aio/transport/sessions.py
    • Added typing.Any, typing.Union, and typing imports for enhanced type hinting.
    • Implemented conditional import and type checking for aiohttp.ClientTimeout.
    • Modified the timeout parameter in the request, get, post, put, and patch methods to accept Union[float, ClientTimeout].
    • Introduced a new total_attempts parameter to the request method, along with updated documentation.
    • Updated the AsyncExponentialBackoff initialization to utilize the new total_attempts parameter for retry control.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@yinghsienwu yinghsienwu changed the title Support timeout as aiohttp.ClientTimeout and total_attempts (max retries) in AsyncAuthorizedSession feat: Support timeout as aiohttp.ClientTimeout and total_attempts (max retries) in AsyncAuthorizedSession Feb 18, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances AsyncAuthorizedSession by allowing aiohttp.ClientTimeout objects to be passed as timeout and by introducing a total_attempts parameter to configure the maximum number of retries. The changes are well-implemented in the core request method.

However, there are a few areas for improvement:

  • The convenience methods (get, post, put, patch) have not been updated to accept and pass through the new total_attempts parameter. This makes the new retry functionality unavailable when using these common methods.
  • The delete method has not been updated at all, and still expects timeout to be a float, and does not support total_attempts. For consistency across the API, it should be updated as well.
  • There are a couple of minor style issues related to indentation and extra newlines.

I've added specific comments with suggestions to address these points. Overall, this is a valuable addition, and with these adjustments, it will be even better.

@@ -255,10 +271,11 @@ async def delete(
headers: Optional[Mapping[str, str]] = None,
max_allowed_time: float = transport._DEFAULT_TIMEOUT_SECONDS,
timeout: float = transport._DEFAULT_TIMEOUT_SECONDS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not be updated to -Union[float, ClientTimeout] = transport._DEFAULT_TIMEOUT_SECONDS

if typing.TYPE_CHECKING:
from aiohttp import ClientTimeout
else:
ClientTimeout: typing.Type = Any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Using ClientTimeout: typing.Type = Any might be interpreted as ClientTimeout being a class type itself.

maybe we use ClientTimeout = Any or ClientTimeout: Any = Any

Copy link
Contributor

@agrawalradhika-cell agrawalradhika-cell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parthea
Copy link
Contributor

parthea commented Feb 20, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces support for aiohttp.ClientTimeout objects and a total_attempts parameter for retries in AsyncAuthorizedSession. The changes are well-implemented, including updated type hints, docstrings, and logic to handle the new parameters. The system tests and unit tests have also been updated to reflect these changes, ensuring proper functionality and coverage. The identified area for improvement, as detailed in the specific comments, is the conditional import logic for ClientTimeout to ensure correct runtime type resolution.

yinghsienwu and others added 3 commits February 20, 2026 11:29
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@agrawalradhika-cell agrawalradhika-cell merged commit 6aab8bc into googleapis:main Feb 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants