Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 2336e64

Browse files
committed
fixed warnings
1 parent 685b62a commit 2336e64

3 files changed

Lines changed: 137 additions & 107 deletions

File tree

google/cloud/bigtable/data/_async/metrics_interceptor.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if CrossSync.is_async:
2929
from grpc.aio import UnaryUnaryClientInterceptor
3030
from grpc.aio import UnaryStreamClientInterceptor
31+
from grpc.aio import AioRpcError
3132
else:
3233
from grpc import UnaryUnaryClientInterceptor
3334
from grpc import UnaryStreamClientInterceptor
@@ -86,12 +87,18 @@ def _end_attempt(operation, exc, metadata):
8687

8788

8889
@CrossSync.convert
89-
async def _get_metadata(source):
90+
async def _get_metadata(source) -> dict[str, str|bytes] | None:
9091
"""Helper to extract metadata from a call or RpcError"""
9192
try:
92-
return (await source.trailing_metadata() or {}) + (
93-
await source.initial_metadata() or {}
94-
)
93+
if isinstance(source, AioRpcError) and CrossSync.is_async:
94+
return {
95+
k:v for k,v
96+
in list(source.trailing_metadata()) + list(source.initial_metadata())
97+
}
98+
else:
99+
return (await source.trailing_metadata() or {}) + (
100+
await source.initial_metadata() or {}
101+
)
95102
except Exception:
96103
# ignore errors while fetching metadata
97104
return None

google/cloud/bigtable/data/_metrics/data_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from dataclasses import dataclass
2626
from dataclasses import field
2727
from grpc import StatusCode
28+
from grpc.aio import AioRpcError
2829

2930
import google.cloud.bigtable.data.exceptions as bt_exceptions
3031
from google.cloud.bigtable_v2.types.response_params import ResponseParams
@@ -389,6 +390,8 @@ def _exc_to_status(exc: BaseException) -> StatusCode:
389390
and exc.__cause__.grpc_status_code is not None
390391
):
391392
return exc.__cause__.grpc_status_code
393+
if isinstance(exc, AioRpcError):
394+
return exc.code()
392395
return StatusCode.UNKNOWN
393396

394397
@staticmethod

0 commit comments

Comments
 (0)