@@ -924,22 +924,17 @@ async def mutate_row(
924924 GoogleAPIError exceptions from any retries that failed
925925 - GoogleAPIError: raised on non-idempotent operations that cannot be
926926 safely retried.
927+ - ValueError if invalid arguments are provided
927928 """
928929 operation_timeout , attempt_timeout = _get_timeouts (
929930 operation_timeout , attempt_timeout , self
930931 )
931932
932- if isinstance (row_key , str ):
933- row_key = row_key .encode ("utf-8" )
934- request = {"table_name" : self .table_name , "row_key" : row_key }
935- if self .app_profile_id :
936- request ["app_profile_id" ] = self .app_profile_id
933+ if not mutations :
934+ raise ValueError ("No mutations provided" )
935+ mutations_list = mutations if isinstance (mutations , list ) else [mutations ]
937936
938- if isinstance (mutations , Mutation ):
939- mutations = [mutations ]
940- request ["mutations" ] = [mutation ._to_dict () for mutation in mutations ]
941-
942- if all (mutation .is_idempotent () for mutation in mutations ):
937+ if all (mutation .is_idempotent () for mutation in mutations_list ):
943938 # mutations are all idempotent and safe to retry
944939 predicate = retries .if_exception_type (
945940 core_exceptions .DeadlineExceeded ,
@@ -972,7 +967,13 @@ def on_error_fn(exc):
972967 metadata = _make_metadata (self .table_name , self .app_profile_id )
973968 # trigger rpc
974969 await deadline_wrapped (
975- request , timeout = attempt_timeout , metadata = metadata , retry = None
970+ row_key = row_key .encode ("utf-8" ) if isinstance (row_key , str ) else row_key ,
971+ mutations = [mutation ._to_pb () for mutation in mutations_list ],
972+ table_name = self .table_name ,
973+ app_profile_id = self .app_profile_id ,
974+ timeout = attempt_timeout ,
975+ metadata = metadata ,
976+ retry = None ,
976977 )
977978
978979 async def bulk_mutate_rows (
@@ -1009,6 +1010,7 @@ async def bulk_mutate_rows(
10091010 Raises:
10101011 - MutationsExceptionGroup if one or more mutations fails
10111012 Contains details about any failed entries in .exceptions
1013+ - ValueError if invalid arguments are provided
10121014 """
10131015 operation_timeout , attempt_timeout = _get_timeouts (
10141016 operation_timeout , attempt_timeout , self
@@ -1065,29 +1067,24 @@ async def check_and_mutate_row(
10651067 - GoogleAPIError exceptions from grpc call
10661068 """
10671069 operation_timeout , _ = _get_timeouts (operation_timeout , None , self )
1068- row_key = row_key .encode ("utf-8" ) if isinstance (row_key , str ) else row_key
10691070 if true_case_mutations is not None and not isinstance (
10701071 true_case_mutations , list
10711072 ):
10721073 true_case_mutations = [true_case_mutations ]
1073- true_case_dict = [m ._to_dict () for m in true_case_mutations or []]
1074+ true_case_list = [m ._to_pb () for m in true_case_mutations or []]
10741075 if false_case_mutations is not None and not isinstance (
10751076 false_case_mutations , list
10761077 ):
10771078 false_case_mutations = [false_case_mutations ]
1078- false_case_dict = [m ._to_dict () for m in false_case_mutations or []]
1079+ false_case_list = [m ._to_pb () for m in false_case_mutations or []]
10791080 metadata = _make_metadata (self .table_name , self .app_profile_id )
10801081 result = await self .client ._gapic_client .check_and_mutate_row (
1081- request = {
1082- "predicate_filter" : predicate ._to_dict ()
1083- if predicate is not None
1084- else None ,
1085- "true_mutations" : true_case_dict ,
1086- "false_mutations" : false_case_dict ,
1087- "table_name" : self .table_name ,
1088- "row_key" : row_key ,
1089- "app_profile_id" : self .app_profile_id ,
1090- },
1082+ true_mutations = true_case_list ,
1083+ false_mutations = false_case_list ,
1084+ predicate_filter = predicate ._to_pb () if predicate is not None else None ,
1085+ row_key = row_key .encode ("utf-8" ) if isinstance (row_key , str ) else row_key ,
1086+ table_name = self .table_name ,
1087+ app_profile_id = self .app_profile_id ,
10911088 metadata = metadata ,
10921089 timeout = operation_timeout ,
10931090 retry = None ,
@@ -1123,25 +1120,21 @@ async def read_modify_write_row(
11231120 operation
11241121 Raises:
11251122 - GoogleAPIError exceptions from grpc call
1123+ - ValueError if invalid arguments are provided
11261124 """
11271125 operation_timeout , _ = _get_timeouts (operation_timeout , None , self )
1128- row_key = row_key .encode ("utf-8" ) if isinstance (row_key , str ) else row_key
11291126 if operation_timeout <= 0 :
11301127 raise ValueError ("operation_timeout must be greater than 0" )
11311128 if rules is not None and not isinstance (rules , list ):
11321129 rules = [rules ]
11331130 if not rules :
11341131 raise ValueError ("rules must contain at least one item" )
1135- # concert to dict representation
1136- rules_dict = [rule ._to_dict () for rule in rules ]
11371132 metadata = _make_metadata (self .table_name , self .app_profile_id )
11381133 result = await self .client ._gapic_client .read_modify_write_row (
1139- request = {
1140- "rules" : rules_dict ,
1141- "table_name" : self .table_name ,
1142- "row_key" : row_key ,
1143- "app_profile_id" : self .app_profile_id ,
1144- },
1134+ rules = [rule ._to_pb () for rule in rules ],
1135+ row_key = row_key .encode ("utf-8" ) if isinstance (row_key , str ) else row_key ,
1136+ table_name = self .table_name ,
1137+ app_profile_id = self .app_profile_id ,
11451138 metadata = metadata ,
11461139 timeout = operation_timeout ,
11471140 retry = None ,
0 commit comments