Skip to content

Commit 1dcb95f

Browse files
mackenziestarrcrwilcox
authored andcommitted
fix(bigtable): add ability to use single-row transactions (#10021)
* fix: add ability to use single-row transactions fixes #10018 * fix: add unit tests for supporting single-row transactions
1 parent c6d953b commit 1dcb95f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

bigtable/google/cloud/bigtable/row.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ def commit(self):
582582
table_name=self._table.name,
583583
row_key=self._row_key,
584584
predicate_filter=self._filter.to_pb(),
585+
app_profile_id=self._table._app_profile_id,
585586
true_mutations=true_mutations,
586587
false_mutations=false_mutations,
587588
)
@@ -908,7 +909,10 @@ def commit(self):
908909

909910
data_client = self._table._instance._client.table_data_client
910911
row_response = data_client.read_modify_write_row(
911-
table_name=self._table.name, row_key=self._row_key, rules=self._rule_pb_list
912+
table_name=self._table.name,
913+
row_key=self._row_key,
914+
rules=self._rule_pb_list,
915+
app_profile_id=self._table._app_profile_id,
912916
)
913917

914918
# Reset modifications after commit-ing request.

bigtable/tests/unit/test_row.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def test_commit(self):
409409
project_id = "project-id"
410410
row_key = b"row_key"
411411
table_name = "projects/more-stuff"
412+
app_profile_id = "app_profile_id"
412413
column_family_id1 = u"column_family_id1"
413414
column_family_id2 = u"column_family_id2"
414415
column_family_id3 = u"column_family_id3"
@@ -420,7 +421,7 @@ def test_commit(self):
420421
client = self._make_client(
421422
project=project_id, credentials=credentials, admin=True
422423
)
423-
table = _Table(table_name, client=client)
424+
table = _Table(table_name, client=client, app_profile_id=app_profile_id)
424425
row_filter = RowSampleFilter(0.33)
425426
row = self._make_one(row_key, table, filter_=row_filter)
426427

@@ -444,6 +445,8 @@ def test_commit(self):
444445
row.delete_cell(column_family_id2, column2, state=True)
445446
row.delete_cells(column_family_id3, row.ALL_COLUMNS, state=True)
446447
result = row.commit()
448+
call_args = api.transport.check_and_mutate_row.call_args.args[0]
449+
self.assertEqual(app_profile_id, call_args.app_profile_id)
447450
self.assertEqual(result, expected_result)
448451
self.assertEqual(row._true_pb_mutations, [])
449452
self.assertEqual(row._false_pb_mutations, [])
@@ -564,6 +567,7 @@ def test_commit(self):
564567
project_id = "project-id"
565568
row_key = b"row_key"
566569
table_name = "projects/more-stuff"
570+
app_profile_id = "app_profile_id"
567571
column_family_id = u"column_family_id"
568572
column = b"column"
569573

@@ -572,7 +576,7 @@ def test_commit(self):
572576
client = self._make_client(
573577
project=project_id, credentials=credentials, admin=True
574578
)
575-
table = _Table(table_name, client=client)
579+
table = _Table(table_name, client=client, app_profile_id=app_profile_id)
576580
row = self._make_one(row_key, table)
577581

578582
# Create request_pb
@@ -593,7 +597,8 @@ def mock_parse_rmw_row_response(row_response):
593597
with _Monkey(MUT, _parse_rmw_row_response=mock_parse_rmw_row_response):
594598
row.append_cell_value(column_family_id, column, value)
595599
result = row.commit()
596-
600+
call_args = api.transport.read_modify_write_row.call_args.args[0]
601+
self.assertEqual(app_profile_id, call_args.app_profile_id)
597602
self.assertEqual(result, expected_result)
598603
self.assertEqual(row._rule_pb_list, [])
599604

@@ -819,9 +824,10 @@ def __init__(self, client=None):
819824

820825

821826
class _Table(object):
822-
def __init__(self, name, client=None):
827+
def __init__(self, name, client=None, app_profile_id=None):
823828
self.name = name
824829
self._instance = _Instance(client)
830+
self._app_profile_id = app_profile_id
825831
self.client = client
826832
self.mutated_rows = []
827833

0 commit comments

Comments
 (0)