Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 8b8a4ca

Browse files
committed
Changed no mutations to raise ValueError instead of status
1 parent 038937a commit 8b8a4ca

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

google/cloud/bigtable/row.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ def commit(self):
446446
"""Makes a ``MutateRow`` API request.
447447
448448
If no mutations have been created in the row, no request is made and a
449-
:class:`~google.rpc.status_pb2.Status` with code INVALID_ARGUMENT is returned
450-
instead.
449+
ValueError is raised instead.
451450
452451
Mutations are applied atomically and in order, meaning that earlier
453452
mutations can be masked / negated by later ones. Cells already present
@@ -466,6 +465,7 @@ def commit(self):
466465
:rtype: :class:`~google.rpc.status_pb2.Status`
467466
:returns: A response status (`google.rpc.status_pb2.Status`)
468467
representing success or failure of the row committed.
468+
:raises: ValueError: if no mutations have been created in the row
469469
"""
470470
try:
471471
self._table._table_impl.mutate_row(self.row_key, self._get_mutations())
@@ -479,12 +479,8 @@ def commit(self):
479479
message=e.message,
480480
details=e.details,
481481
)
482-
except ValueError as e:
483-
# _table_impl.mutate_row raises a ValueError if invalid arguments are provided.
484-
return status_pb2.Status(
485-
code=code_pb2.INVALID_ARGUMENT,
486-
message=str(e),
487-
)
482+
except ValueError:
483+
raise
488484
finally:
489485
self.clear()
490486

tests/system/v2_client/test_data_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,10 +1092,10 @@ def test_table_direct_row_input_errors(data_table, rows_to_delete):
10921092
resp = row.commit()
10931093
assert resp.code == StatusCode.INVALID_ARGUMENT.value[0]
10941094

1095-
# Not having any mutations gives an INVALID_ARGUMENT
1095+
# Not having any mutations raises a ValueError
10961096
row.clear()
1097-
resp = row.commit()
1098-
assert resp.code == StatusCode.INVALID_ARGUMENT.value[0]
1097+
with pytest.raises(ValueError):
1098+
resp = row.commit()
10991099

11001100

11011101
def test_table_conditional_row_input_errors(data_table, rows_to_delete):

tests/unit/v2_client/test_row.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,8 @@ def test_direct_row_commit_with_invalid_argument():
494494
client._table_data_client._gapic_client = api
495495

496496
# Perform the method and check the result.
497-
result = row.commit()
498-
assert row._mutations == []
499-
assert result == status_pb2.Status(
500-
code=code_pb2.Code.INVALID_ARGUMENT, message="No mutations provided"
501-
)
497+
with pytest.raises(ValueError, match="No mutations provided"):
498+
row.commit()
502499
api.mutate_row.assert_not_called()
503500

504501

0 commit comments

Comments
 (0)