Skip to content

Commit

Permalink
feat: add response status to DirectRow.commit() (#128)
Browse files Browse the repository at this point in the history
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigtable/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)

Fixes #127  🦕
  • Loading branch information
ryanyuan authored Sep 22, 2020
1 parent d16f1f0 commit 2478bb8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion google/cloud/bigtable/row.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)]

0 comments on commit 2478bb8

Please sign in to comment.