From 47fc3da451931462216f3a740e8d092b23806075 Mon Sep 17 00:00:00 2001 From: IlyaFaer Date: Wed, 11 Aug 2021 12:33:19 +0300 Subject: [PATCH 1/3] fix(samples): batch_update() results processing error --- samples/samples/snippets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/samples/samples/snippets.py b/samples/samples/snippets.py index 0cc68856ea..53c130c05f 100644 --- a/samples/samples/snippets.py +++ b/samples/samples/snippets.py @@ -1529,7 +1529,11 @@ def update_with_batch_dml(instance_id, database_id): ) def update_albums(transaction): - row_cts = transaction.batch_update([insert_statement, update_statement]) + status, row_cts = transaction.batch_update([insert_statement, update_statement]) + + # check response status and process error (if occurred) + # if status.code != rpc.code_pb2.OK: + # ... print("Executed {} SQL statements using Batch DML.".format(len(row_cts))) From 273ba7bbacccc704e019f4cfd99213bf1dcda18b Mon Sep 17 00:00:00 2001 From: IlyaFaer Date: Thu, 12 Aug 2021 12:02:10 +0300 Subject: [PATCH 2/3] fix the comment --- samples/samples/snippets.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/samples/samples/snippets.py b/samples/samples/snippets.py index 53c130c05f..4baa51f6b6 100644 --- a/samples/samples/snippets.py +++ b/samples/samples/snippets.py @@ -1509,6 +1509,8 @@ def delete_data_with_partitioned_dml(instance_id, database_id): def update_with_batch_dml(instance_id, database_id): """Updates sample data in the database using Batch DML. """ # [START spanner_dml_batch_update] + from google.rpc.code_pb2 import OK + # instance_id = "your-spanner-instance" # database_id = "your-spanner-db-id" @@ -1531,9 +1533,11 @@ def update_with_batch_dml(instance_id, database_id): def update_albums(transaction): status, row_cts = transaction.batch_update([insert_statement, update_statement]) - # check response status and process error (if occurred) - # if status.code != rpc.code_pb2.OK: - # ... + if status.code != OK: + # Do handling here. + # Note: the error will still be raised when + # commit is called by `run_in_transaction`. + return print("Executed {} SQL statements using Batch DML.".format(len(row_cts))) From 50071b450d1c13e4bb5e8f910ec6e9de2b4b13d9 Mon Sep 17 00:00:00 2001 From: IlyaFaer Date: Thu, 12 Aug 2021 12:04:37 +0300 Subject: [PATCH 3/3] minor fix --- samples/samples/snippets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/samples/snippets.py b/samples/samples/snippets.py index 4baa51f6b6..53a9e5c58d 100644 --- a/samples/samples/snippets.py +++ b/samples/samples/snippets.py @@ -1535,8 +1535,8 @@ def update_albums(transaction): if status.code != OK: # Do handling here. - # Note: the error will still be raised when - # commit is called by `run_in_transaction`. + # Note: the exception will still be raised when + # `commit` is called by `run_in_transaction`. return print("Executed {} SQL statements using Batch DML.".format(len(row_cts)))