Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add response status to DirectRow.commit() #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions tests/unit/test_row.py
Expand Up @@ -359,6 +359,29 @@ def test_commit(self):
row.commit()
self.assertEqual(table.mutated_rows, [row])

def test_commit_with_exception(self):
from google.rpc import status_pb2

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)
result = row.commit()
expected = status_pb2.Status(code=0)
self.assertEqual(result, expected)


class TestConditionalRow(unittest.TestCase):
@staticmethod
Expand Down Expand Up @@ -832,4 +855,7 @@ def __init__(self, name, client=None, app_profile_id=None):
self.mutated_rows = []

def mutate_rows(self, rows):
from google.rpc import status_pb2

self.mutated_rows.extend(rows)
return [status_pb2.Status(code=0)]