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

Commit 829c385

Browse files
committed
Merge branch 'add-increment-sample' of github.com:KasiaStrz/python-bigtable into add-increment-sample
2 parents d39e422 + 44c983d commit 829c385

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

samples/snippets/writes/write_increment_async.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ async def write_increment_async(project_id, instance_id, table_id):
77
"""Increments a value in a Bigtable table using the async client."""
88
async with BigtableDataClientAsync(project=project_id) as client:
99
table = client.get_table(instance_id, table_id)
10-
# Define the row key as a byte string
11-
row_key = b"unique_device_ids_1"
10+
row_key = "unique_device_ids_1"
1211
try:
1312
async with table.mutations_batcher() as batcher:
1413
# The AddToCell mutation increments the value of a cell.
@@ -18,10 +17,10 @@ async def write_increment_async(project_id, instance_id, table_id):
1817
qualifier="odometer",
1918
value=32304
2019
)
21-
await batcher.append(RowMutationEntry(row_key, [reading]))
22-
print(f"Successfully incremented row {row_key.decode('utf-8')}.")
20+
await batcher.append(RowMutationEntry(row_key.encode("utf-8"), [reading]))
2321
except MutationsExceptionGroup as e:
24-
print(f"Failed to increment row {row_key.decode('utf-8')}")
22+
# MutationsExceptionGroup contains a FailedMutationEntryError for
23+
# each mutation that failed.
2524
for sub_exception in e.exceptions:
2625
failed_entry: RowMutationEntry = sub_exception.entry
2726
cause: Exception = sub_exception.__cause__

0 commit comments

Comments
 (0)