Skip to content

Commit

Permalink
feat: add response status to DirectRow.commit()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanyuan committed Sep 18, 2020
1 parent e55ca07 commit 666a908
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion google/cloud/bigtable/row.py
Expand Up @@ -457,12 +457,18 @@ def commit(self):
:end-before: [END bigtable_row_commit]
:dedent: 4
:rtype: :class:`~google.rpc.status_pb2.Status`
:returns: A response status (`google.rpc.status_pb2.Status`)
representing success or failure of the row committed.
:raises: :exc:`~.table.TooManyMutationsError` if the number of
mutations is greater than 100,000.
"""
self._table.mutate_rows([self])
response = self._table.mutate_rows([self])

self.clear()

return response[0]

def clear(self):
"""Removes all currently accumulated mutations on the current row.
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_row.py
Expand Up @@ -359,6 +359,28 @@ def test_commit(self):
row.commit()
self.assertEqual(table.mutated_rows, [row])

@mock.patch("google.cloud.bigtable.table.Table.mutate_rows")
def test_commit_with_exception(self, mock_mutate_rows):
project_id = "project-id"
row_key = b"row_key"
table_name = "projects/more-stuff"
column_family_id = u"column_family_id"
column = b"column"

credentials = _make_credentials()
client = self._make_client(
project=project_id, credentials=credentials, admin=True
)
table = _Table(table_name, client=client)
row = self._make_one(row_key, table)
value = b"bytes-value"

# Perform the method and check the result.
row.set_cell(column_family_id, column, value)
from google.rpc import status_pb2
result = row.commit()
self.assertIsInstance(result, status_pb2.Status)


class TestConditionalRow(unittest.TestCase):
@staticmethod
Expand Down Expand Up @@ -833,3 +855,5 @@ def __init__(self, name, client=None, app_profile_id=None):

def mutate_rows(self, rows):
self.mutated_rows.extend(rows)
from google.rpc import status_pb2
return [status_pb2.Status()]

0 comments on commit 666a908

Please sign in to comment.