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

Commit 36cfaaf

Browse files
committed
Addressed review feedback + fixed system tests.
1 parent 8cb8af0 commit 36cfaaf

3 files changed

Lines changed: 14 additions & 42 deletions

File tree

google/cloud/bigtable/row.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,16 @@ def _delete_cells(self, column_family_id, columns, time_range=None, state=None):
210210
:param state: (Optional) The state that is passed along to
211211
:meth:`_get_mutations`.
212212
"""
213-
mutations_list = self._get_mutations(state)
214213
if columns is self.ALL_COLUMNS:
215214
self._get_mutations(state).append(
216215
mutations.DeleteAllFromFamily(family_to_delete=column_family_id)
217216
)
218217
else:
219218
start_timestamp_micros = None
220219
end_timestamp_micros = None
221-
if time_range is not None:
222-
timestamps = time_range._to_dict()
223-
start_timestamp_micros = timestamps.get("start_timestamp_micros")
224-
end_timestamp_micros = timestamps.get("end_timestamp_micros")
220+
timestamps = time_range._to_dict() if time_range else {}
221+
start_timestamp_micros = timestamps.get("start_timestamp_micros")
222+
end_timestamp_micros = timestamps.get("end_timestamp_micros")
225223

226224
to_append = []
227225
for column in columns:
@@ -237,7 +235,7 @@ def _delete_cells(self, column_family_id, columns, time_range=None, state=None):
237235

238236
# We don't add the mutations until all columns have been
239237
# processed without error.
240-
mutations_list.extend(to_append)
238+
self._get_mutations(state).extend(to_append)
241239

242240

243241
class DirectRow(_SetDeleteRow):
@@ -973,9 +971,9 @@ def _parse_rmw_row_response(row_response):
973971
"""
974972
result = {}
975973
for cell in row_response.cells:
976-
result.setdefault(cell.family, {}).setdefault(cell.qualifier, []).append(
977-
(cell.value, _datetime_from_microseconds(cell.timestamp_micros))
978-
)
974+
column_family = result.setdefault(cell.family, {})
975+
column = column_family.setdefault(cell.qualifier, [])
976+
column.append((cell.value, _datetime_from_microseconds(cell.timestamp_micros)))
979977
return result
980978

981979

tests/system/v2_client/test_data_api.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,39 +1144,17 @@ def test_table_append_row_input_errors(data_table, rows_to_delete):
11441144
rows_to_delete.append(data_table.direct_row(ROW_KEY))
11451145

11461146
# Column names should be convertible to bytes (str or bytes)
1147-
with pytest.raises(TypeError):
1147+
with pytest.raises(AttributeError):
11481148
row.append_cell_value(COLUMN_FAMILY_ID1, INT_COL_NAME, CELL_VAL1)
11491149

1150-
with pytest.raises(TypeError):
1150+
with pytest.raises(AttributeError):
11511151
row.increment_cell_value(COLUMN_FAMILY_ID1, INT_COL_NAME, 1)
11521152

1153-
# Unicode for column name and value
1154-
with pytest.raises(UnicodeEncodeError):
1155-
row.append_cell_value(COLUMN_FAMILY_ID1, JOY_EMOJI, CELL_VAL1)
1156-
1157-
with pytest.raises(UnicodeEncodeError):
1158-
row.append_cell_value(COLUMN_FAMILY_ID1, COL_NAME1, JOY_EMOJI)
1159-
1160-
with pytest.raises(UnicodeEncodeError):
1161-
row.increment_cell_value(COLUMN_FAMILY_ID1, JOY_EMOJI, 1)
1162-
1163-
# Non-integer cell values for increment_cell_value
11641153
with pytest.raises(ValueError):
11651154
row.increment_cell_value(COLUMN_FAMILY_ID1, COL_NAME1, OVERFLOW_INT_CELL_VAL)
11661155

1167-
# increment_cell_value does not do input validation on the int_value, instead using
1168-
# proto-plus to do validation.
1169-
row.increment_cell_value(COLUMN_FAMILY_ID1, COL_NAME1, FLOAT_CELL_VAL)
1170-
row.increment_cell_value(COLUMN_FAMILY_ID1, COL_NAME2, FLOAT_CELL_VAL2)
1171-
row.commit()
1172-
1173-
row_data = data_table.read_row(ROW_KEY)
1174-
assert row_data.cells[COLUMN_FAMILY_ID1][COL_NAME1][0].value == int(
1175-
FLOAT_CELL_VAL
1176-
).to_bytes(8, byteorder="big", signed=True)
1177-
assert row_data.cells[COLUMN_FAMILY_ID1][COL_NAME2][0].value == int(
1178-
FLOAT_CELL_VAL2
1179-
).to_bytes(8, byteorder="big", signed=True)
1156+
with pytest.raises(TypeError):
1157+
row.increment_cell_value(COLUMN_FAMILY_ID1, COL_NAME1, FLOAT_CELL_VAL)
11801158

11811159
# Can't have more than MAX_MUTATIONS mutations, but only enforced after
11821160
# a row.commit

tests/unit/v2_client/test_row.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,9 @@ def _delete_cells_helper(time_range=None):
303303

304304
expected_mutation = DeleteRangeFromColumn(family=column_family_id, qualifier=column)
305305
if time_range is not None:
306-
time_range_pb = time_range._to_pb()
307-
if time_range_pb.start_timestamp_micros:
308-
expected_mutation.start_timestamp_micros = (
309-
time_range_pb.start_timestamp_micros
310-
)
311-
if time_range_pb.end_timestamp_micros:
312-
expected_mutation.end_timestamp_micros = time_range_pb.end_timestamp_micros
306+
timestamps = time_range._to_dict()
307+
expected_mutation.start_timestamp_micros = timestamps.get("start_timestamp_micros")
308+
expected_mutation.end_timestamp_micros = timestamps.get("end_timestamp_micros")
313309
_assert_mutations_equal(row._mutations, [expected_mutation])
314310

315311

0 commit comments

Comments
 (0)