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

Commit 8ac92d0

Browse files
committed
fixed bug in parsing bulk mutations errors
1 parent 6caba34 commit 8ac92d0

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,14 @@ def _exc_to_status(exc: Exception) -> StatusCode:
410410
Args:
411411
- exc: The exception to extract the status code from.
412412
"""
413-
if isinstance(exc, bt_exceptions._BigtableExceptionGroup):
413+
# parse bigtable custom exceptions
414+
if isinstance(exc, (bt_exceptions.MutationsExceptionGroup, bt_exceptions.ShardedReadRowsExceptionGroup)) and exc.exceptions:
415+
# grab the RetryExceptionGroup from the most last failed mutation/shard
416+
exc = exc.exceptions[-1].__cause__
417+
if isinstance(exc, bt_exceptions.RetryExceptionGroup):
418+
# grab the last exception in the retry group
414419
exc = exc.exceptions[-1]
420+
# parse grpc exceptions
415421
if hasattr(exc, "grpc_status_code") and exc.grpc_status_code is not None:
416422
return exc.grpc_status_code
417423
if (

tests/system/data/test_metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ def side_effect(*args, **kwargs):
134134
async with table_with_profile("retry_then_timeout") as table:
135135
stubs = {k:v for k,v in _get_stubs_for_table(table).items() if k not in non_retryable_rpcs}
136136
for rpc_name, stub_list in stubs.items():
137-
with mock.patch("google.cloud.bigtable.data._helpers.exp_sleep_generator", side_effect=[0, 0, 5]):
138137
with mock.patch(f"google.cloud.bigtable_v2.BigtableAsyncClient.{rpc_name}", side_effect=ServiceUnavailable("test")):
139138
for stub in stub_list:
140-
with pytest.raises((DeadlineExceeded, MutationsExceptionGroup)):
141-
await stub(operation_timeout=0.5, retryable_errors=(ServiceUnavailable,))
139+
with mock.patch("google.cloud.bigtable.data._helpers.exponential_sleep_generator", return_value=iter([0.01, 0.01, 5])):
140+
with pytest.raises((DeadlineExceeded, MutationsExceptionGroup)):
141+
await stub(operation_timeout=0.5, retryable_errors=(ServiceUnavailable,))
142142

143143
# Calls hit retryable errors, then hit terminal exception
144144
print("populating retryable then terminal error rpcs...")

0 commit comments

Comments
 (0)