File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -1511,6 +1511,8 @@ def delete_data_with_partitioned_dml(instance_id, database_id):
1511
1511
def update_with_batch_dml (instance_id , database_id ):
1512
1512
"""Updates sample data in the database using Batch DML. """
1513
1513
# [START spanner_dml_batch_update]
1514
+ from google .rpc .code_pb2 import OK
1515
+
1514
1516
# instance_id = "your-spanner-instance"
1515
1517
# database_id = "your-spanner-db-id"
1516
1518
@@ -1531,7 +1533,13 @@ def update_with_batch_dml(instance_id, database_id):
1531
1533
)
1532
1534
1533
1535
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
1535
1543
1536
1544
print ("Executed {} SQL statements using Batch DML." .format (len (row_cts )))
1537
1545
You can’t perform that action at this time.
0 commit comments