def commit(self): """Makes a ``CheckAndMutateRow`` API request. If no mutations have been created in the row, no request is made. The mutations will be applied conditionally, based on whether the filter matches any cells in the :class:`ConditionalRow` or not. (Each method which adds a mutation has a ``state`` parameter for this purpose.) Mutations are applied atomically and in order, meaning that earlier mutations can be masked / negated by later ones. Cells already present in the row are left unchanged unless explicitly changed by a mutation. After committing the accumulated mutations, resets the local mutations. :rtype: bool :returns: Flag indicating if the filter was matched (which also indicates which set of mutations were applied by the server). :raises: :class:`ValueError <exceptions.ValueError>` if the number of mutations exceeds the :data:`MAX_MUTATIONS`. """ true_mutations = self._get_mutations(state=True) false_mutations = self._get_mutations(state=False) num_true_mutations = len(true_mutations) num_false_mutations = len(false_mutations) if num_true_mutations == 0 and num_false_mutations == 0: return if (num_true_mutations > MAX_MUTATIONS or num_false_mutations > MAX_MUTATIONS): raise ValueError( 'Exceed the maximum allowable mutations (%d). Had %s true ' 'mutations and %d false mutations.' % (MAX_MUTATIONS, num_true_mutations, num_false_mutations)) request_pb = messages_v2_pb2.CheckAndMutateRowRequest( table_name=self._table.name, row_key=self._row_key, predicate_filter=self._filter.to_pb(), true_mutations=true_mutations, false_mutations=false_mutations, ) # We expect a `.messages_v2_pb2.CheckAndMutateRowResponse` client = self._table._instance._client resp = client._data_stub.CheckAndMutateRow(request_pb, client.timeout_seconds) self.clear() return resp.predicate_matched
def _CheckAndMutateRowRequestPB(*args, **kw): from gcloud.bigtable._generated import (bigtable_pb2 as messages_v2_pb2) return messages_v2_pb2.CheckAndMutateRowRequest(*args, **kw)