Repository navigation
fix(api-core): preserve errors raised by async stream factories - #19323
Open
jaideeppyne wants to merge 1 commit into
Open
jaideeppyne wants to merge 1 commit into
jaideeppyne wants to merge 1 commit into
Conversation
Signed-off-by: jaideeppyne <jaideeppyne1997@gmail.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request replaces a try-except block in retry_target_stream with an explicit check using inspect.isawaitable to determine if the target output is awaitable, and adds corresponding unit tests. The review feedback suggests optimizing startup performance by avoiding the import of the inspect module, recommending the use of collections.abc.Awaitable with isinstance instead.
|
|
||
| import asyncio | ||
| import functools | ||
| import inspect |
Contributor
| *init_args, **init_kwargs | ||
| ) | ||
| try: | ||
| if inspect.isawaitable(target_output): |
Contributor
There was a problem hiding this comment.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An async stream factory that raises
TypeErrorwhile being awaited currently surfaces an unrelatedAttributeErroron__aiter__. The wrapper catches everyTypeErrorfrom the await and assumes the output was not awaitable. As a result, the original failure is lost and a retry predicate for that error never receives it.Use
inspect.isawaitableto choose the unwrap path before awaiting the factory. Errors from that await then flow through the existing retry/error handling. Direct async iterables continue to use their iterator directly.The four new regression cases cover a native coroutine and a custom awaitable, each with retryable and non-retryable setup errors. They verify the original exception identity, error callback, retry delay and successful values after retry. All four fail on the original code with
AttributeError.Validation on Python 3.13:
google-auth==2.14.1: 1,932 passed, 93 skipped.git diff --checkpass.Prepared and tested with OpenAI Codex assistance.