fix: await response.code() and use sys.exc_info() in async gRPC interceptor#1066
Open
danishashko wants to merge 1 commit intogoogleads:mainfrom
Open
fix: await response.code() and use sys.exc_info() in async gRPC interceptor#1066danishashko wants to merge 1 commit intogoogleads:mainfrom
danishashko wants to merge 1 commit intogoogleads:mainfrom
Conversation
grpc.aio.Call objects don't have .exception() (AttributeError on issue googleads#1059). response.code() is a coroutine in async gRPC and must be awaited.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
bobhancockg
approved these changes
Apr 1, 2026
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.
Fixes #1059
Two bugs in
_AsyncExceptionInterceptor._handle_grpc_failure_async():Bug 1:
response.exception()raisesAttributeErrorgrpc.aio.Callobjects don't have an.exception()method. That method only exists on synchronousgrpc.Futureobjects. When a timeout or temporary service error triggers the async interceptor, callingresponse.exception()raisesAttributeError: 'UnaryUnaryCall' object has no attribute 'exception', masking the original gRPC error entirely.Fix: use
sys.exc_info()[1]to capture the live exception — this works since_handle_grpc_failure_asyncis always called from within anexcept grpc.RpcErrorblock in the async wrappers.Bug 2:
response.code()not awaitedIn
grpc.aio,Call.code()is a coroutine and must be awaited. Withoutawait,status_codewould be a coroutine object, making thestatus_code not in _RETRY_STATUS_CODEScheck always evaluate toTrue, meaning retry-able errors (INTERNAL, RESOURCE_EXHAUSTED) would incorrectly be parsed as GoogleAdsFailures instead of being re-raised as-is.Other cleanup:
_RETRY_STATUS_CODESfrominterceptor.pyinstead of redefining it locally