Skip to content

Commit bdd5f8b

Browse files
Ilya Gurovlarkee
Ilya Gurov
andauthored
fix(samples): batch_update() results processing error (#484)
* fix(samples): batch_update() results processing error * fix the comment * minor fix Co-authored-by: larkee <31196561+larkee@users.noreply.github.com>
1 parent d557a8d commit bdd5f8b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

‎samples/samples/snippets.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,8 @@ def delete_data_with_partitioned_dml(instance_id, database_id):
15111511
def update_with_batch_dml(instance_id, database_id):
15121512
"""Updates sample data in the database using Batch DML. """
15131513
# [START spanner_dml_batch_update]
1514+
from google.rpc.code_pb2 import OK
1515+
15141516
# instance_id = "your-spanner-instance"
15151517
# database_id = "your-spanner-db-id"
15161518

@@ -1531,7 +1533,13 @@ def update_with_batch_dml(instance_id, database_id):
15311533
)
15321534

15331535
def update_albums(transaction):
1534-
row_cts = transaction.batch_update([insert_statement, update_statement])
1536+
status, row_cts = transaction.batch_update([insert_statement, update_statement])
1537+
1538+
if status.code != OK:
1539+
# Do handling here.
1540+
# Note: the exception will still be raised when
1541+
# `commit` is called by `run_in_transaction`.
1542+
return
15351543

15361544
print("Executed {} SQL statements using Batch DML.".format(len(row_cts)))
15371545

0 commit comments

Comments
 (0)