Skip to content

fix: await response.code() and use sys.exc_info() in async gRPC interceptor#1066

Open
danishashko wants to merge 1 commit intogoogleads:mainfrom
danishashko:fix/async-exception-interceptor
Open

fix: await response.code() and use sys.exc_info() in async gRPC interceptor#1066
danishashko wants to merge 1 commit intogoogleads:mainfrom
danishashko:fix/async-exception-interceptor

Conversation

@danishashko
Copy link
Copy Markdown

Fixes #1059

Two bugs in _AsyncExceptionInterceptor._handle_grpc_failure_async():

Bug 1: response.exception() raises AttributeError

grpc.aio.Call objects don't have an .exception() method. That method only exists on synchronous grpc.Future objects. When a timeout or temporary service error triggers the async interceptor, calling response.exception() raises AttributeError: '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_async is always called from within an except grpc.RpcError block in the async wrappers.

Bug 2: response.code() not awaited

In grpc.aio, Call.code() is a coroutine and must be awaited. Without await, status_code would be a coroutine object, making the status_code not in _RETRY_STATUS_CODES check always evaluate to True, meaning retry-able errors (INTERNAL, RESOURCE_EXHAUSTED) would incorrectly be parsed as GoogleAdsFailures instead of being re-raised as-is.

Other cleanup:

  • Removed leftover reasoning comments that were accidentally committed
  • Import _RETRY_STATUS_CODES from interceptor.py instead of redefining it locally

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.
@danishashko danishashko requested a review from a team as a code owner April 1, 2026 14:12
@danishashko danishashko requested review from BenRKarl and dorasun April 1, 2026 14:12
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 1, 2026

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.

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.

Uploading conversions async - AttributeError: 'UnaryUnaryCall' object has no attribute 'exception'

2 participants