Repository navigation
Description
When an RPC made through an async service client (get_service(..., is_async=True)) fails, asyncio reports Task exception was never retrieved for the task that runs _AsyncLoggingInterceptor._log_request_async. This happens for every failed unary-unary call, whatever the status code (we first saw it with RESOURCE_EXHAUSTED). The caller still receives the error normally; the extra exception comes from the library's own fire-and-forget logging task.
The cause is the failure check in _log_request_async (google/ads/googleads/interceptors/logging_interceptor.py), as changed by #1061 for #1059:
try:
if hasattr(response, "exception"):
exception = response.code()
else:
await response.code()
exception = None
except Exception as ex:
exception = ex
if exception:
self.log_failed_request_async(...)
else:
result = None
if not hasattr(response, "read"):
result = await response
self.log_successful_request_async(...)No grpc.aio call class has an exception attribute (UnaryUnaryCall, UnaryStreamCall, InterceptedUnaryUnaryCall and InterceptedUnaryStreamCall all return False for hasattr(cls, "exception")), so the else arm always runs. await response.code() returns the status code without raising, the result is discarded, and exception is set to None. A failed call therefore takes the success branch:
- Unary-unary:
result = await responseraises theAioRpcErrorinside the logging task. Nothing awaits that task, so asyncio logs "Task exception was never retrieved", and the failure summary line (log_failed_request_async) is never written. - Unary-stream: the call has
read, so nothing is awaited and the failed request is logged throughlog_successful_request_asyncwithIsFault: False.
Note that the first arm would not work either if it were reached: response.code() on a grpc.aio call is a coroutine, and grpc.StatusCode.OK is truthy, so if exception: cannot distinguish success from failure.
A possible fix is to compare the awaited status code with grpc.StatusCode.OK and take the failure branch otherwise, for example:
code = await response.code()
if code != grpc.StatusCode.OK:
self.log_failed_request_async(..., exception=<AioRpcError built from the call>)log_failed_request_async currently expects an exception object (_parse_exception_to_str_async, _get_fault_message_async), so it would need either the AioRpcError (obtainable with try: await response / except grpc.aio.AioRpcError) or to read details() / debug_error_string() from the call.
Steps to Reproduce:
No valid credentials are needed; any failing RPC triggers it.
import asyncio
import logging
import google.ads.googleads
from google.ads.googleads.client import GoogleAdsClient
from google.oauth2.credentials import Credentials
logging.basicConfig(level=logging.WARNING)
async def main() -> None:
client = GoogleAdsClient(
credentials=Credentials(token="invalid-token"),
developer_token="invalid",
use_proto_plus=True,
)
service = client.get_service("CustomerService", is_async=True)
try:
await service.list_accessible_customers()
except Exception as ex:
print("caught by caller:", type(ex).__name__)
await asyncio.sleep(0.5)
print("google-ads", google.ads.googleads.VERSION)
asyncio.run(main())Output:
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-4' coro=<_AsyncLoggingInterceptor._log_request_async() done, defined at .../google/ads/googleads/interceptors/logging_interceptor.py:431> exception=<AioRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "Request had invalid authentication credentials. ..."
debug_error_string = "UNAUTHENTICATED:Request had invalid authentication credentials. ..."
>>
Traceback (most recent call last):
File ".../google/ads/googleads/interceptors/logging_interceptor.py", line 508, in _log_request_async
result = await response
^^^^^^^^^^^^^^
File ".../grpc/aio/_call.py", line 333, in __await__
raise _create_rpc_error(
...<2 lines>...
)
grpc.aio._call.AioRpcError: <AioRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
...
>
google-ads 35.1.0
caught by caller: Unauthenticated
No Request made: ... IsFault: True warning is logged for the failed request.
Expected behavior:
A failed async RPC is logged once through the failure path (the IsFault: True summary at WARNING), as the sync LoggingInterceptor does, and the logging task finishes without raising.
Client library version and API version:
Client library version: 35.1.0 (latest release; the same code is on main as of 2026-11-12)
Google Ads API version: v26 (library default)
google-ads==35.1.0
grpcio==1.85.1
google-api-core==2.44.0
Python 3.14.10 (macOS arm64)
We first observed it in production on 33.0.0 (Linux, API v23), where the behaviour is identical.
Request/Response Logs:
Not applicable: the bug is that the failure log line is not produced. The asyncio error output is included above.
Anything else we should know about your project / environment:
Workaround: set the google.ads.googleads.client logger above WARNING, because the task is only created when logger.isEnabledFor(logging.WARNING):
logging.getLogger("google.ads.googleads.client").setLevel(logging.ERROR)This disables all request logging from the library.
Activity