1717from typing import Set
1818import warnings
1919
20- from google .api_core .exceptions import GoogleAPICallError
2120from google .api_core .exceptions import Aborted
2221from google .api_core .exceptions import DeadlineExceeded
2322from google .api_core .exceptions import NotFound
3130from google .cloud .bigtable .column_family import _gc_rule_from_pb
3231from google .cloud .bigtable .column_family import ColumnFamily
3332from google .cloud .bigtable .data ._helpers import TABLE_DEFAULT
34- from google .cloud .bigtable .data .exceptions import (
35- RetryExceptionGroup ,
36- MutationsExceptionGroup ,
33+ from google .cloud .bigtable .data ._helpers import (
34+ _get_statuses_from_mutations_exception_group ,
3735)
38- from google .cloud .bigtable .data .read_rows_query import ReadRowsQuery
36+ from google .cloud .bigtable .data .exceptions import MutationsExceptionGroup
3937from google .cloud .bigtable .data .mutations import RowMutationEntry
38+ from google .cloud .bigtable .data .read_rows_query import ReadRowsQuery
4039from google .cloud .bigtable .batcher import MutationsBatcher
4140from google .cloud .bigtable .batcher import FLUSH_COUNT , MAX_MUTATION_SIZE
4241from google .cloud .bigtable .encryption_info import EncryptionInfo
@@ -767,9 +766,9 @@ def mutate_rows(self, rows, retry=DEFAULT_RETRY, timeout=DEFAULT):
767766 mutation_entries = [
768767 RowMutationEntry (row .row_key , row ._get_mutations ()) for row in rows
769768 ]
770- return_statuses = [status_pb2 .Status (code = code_pb2 .Code .OK )] * len (
769+ return_statuses = [status_pb2 .Status (code = code_pb2 .Code .UNKNOWN )] * len (
771770 mutation_entries
772- ) # By default, return status OKs for everything
771+ )
773772
774773 try :
775774 self ._table_impl .bulk_mutate_rows (
@@ -779,41 +778,15 @@ def mutate_rows(self, rows, retry=DEFAULT_RETRY, timeout=DEFAULT):
779778 retryable_errors = retryable_errors ,
780779 )
781780 except MutationsExceptionGroup as mut_exc_group :
782- # We exception handle as follows:
783- #
784- # 1. Each exception in the error group is a FailedMutationEntryError, and its
785- # cause is either a singular exception or a RetryExceptionGroup consisting of
786- # multiple exceptions.
787- #
788- # 2. In the case of a singular exception, if the error does not have a gRPC status
789- # code, we return a status code of UNKNOWN.
790- #
791- # 3. In the case of a RetryExceptionGroup, we use terminal exception in the exception
792- # group and process that.
793- for error in mut_exc_group .exceptions :
794- cause = error .__cause__
795- if isinstance (cause , RetryExceptionGroup ):
796- return_statuses [error .index ] = self ._get_status (
797- cause .exceptions [- 1 ]
798- )
799- else :
800- return_statuses [error .index ] = self ._get_status (cause )
801-
802- return return_statuses
803-
804- @staticmethod
805- def _get_status (error ):
806- if isinstance (error , GoogleAPICallError ) and error .grpc_status_code is not None :
807- return status_pb2 .Status (
808- code = error .grpc_status_code .value [0 ],
809- message = error .message ,
810- details = error .details ,
781+ return_statuses = _get_statuses_from_mutations_exception_group (
782+ mut_exc_group , len (mutation_entries )
783+ )
784+ else :
785+ return_statuses = [status_pb2 .Status (code = code_pb2 .Code .OK )] * len (
786+ mutation_entries
811787 )
812788
813- return status_pb2 .Status (
814- code = code_pb2 .Code .UNKNOWN ,
815- message = str (error ),
816- )
789+ return return_statuses
817790
818791 def sample_row_keys (self ):
819792 """Read a sample of row keys in the table.
0 commit comments