Skip to content

Commit 2478bb8

Browse files
authored
feat: add response status to DirectRow.commit() (#128)
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 🦕
1 parent d16f1f0 commit 2478bb8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

google/cloud/bigtable/row.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,18 @@ def commit(self):
457457
:end-before: [END bigtable_row_commit]
458458
:dedent: 4
459459
460+
:rtype: :class:`~google.rpc.status_pb2.Status`
461+
:returns: A response status (`google.rpc.status_pb2.Status`)
462+
representing success or failure of the row committed.
460463
:raises: :exc:`~.table.TooManyMutationsError` if the number of
461464
mutations is greater than 100,000.
462465
"""
463-
self._table.mutate_rows([self])
466+
response = self._table.mutate_rows([self])
467+
464468
self.clear()
465469

470+
return response[0]
471+
466472
def clear(self):
467473
"""Removes all currently accumulated mutations on the current row.
468474

tests/unit/test_row.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,29 @@ def test_commit(self):
359359
row.commit()
360360
self.assertEqual(table.mutated_rows, [row])
361361

362+
def test_commit_with_exception(self):
363+
from google.rpc import status_pb2
364+
365+
project_id = "project-id"
366+
row_key = b"row_key"
367+
table_name = "projects/more-stuff"
368+
column_family_id = u"column_family_id"
369+
column = b"column"
370+
371+
credentials = _make_credentials()
372+
client = self._make_client(
373+
project=project_id, credentials=credentials, admin=True
374+
)
375+
table = _Table(table_name, client=client)
376+
row = self._make_one(row_key, table)
377+
value = b"bytes-value"
378+
379+
# Perform the method and check the result.
380+
row.set_cell(column_family_id, column, value)
381+
result = row.commit()
382+
expected = status_pb2.Status(code=0)
383+
self.assertEqual(result, expected)
384+
362385

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

834857
def mutate_rows(self, rows):
858+
from google.rpc import status_pb2
859+
835860
self.mutated_rows.extend(rows)
861+
return [status_pb2.Status(code=0)]

0 commit comments

Comments
 (0)