From 086e7b44fba990994dd29f3a1734623ce613c68a Mon Sep 17 00:00:00 2001 From: Sakthivel Subramanian Date: Sun, 5 Jul 2026 17:23:34 +0000 Subject: [PATCH] test(spanner): await database calls in async snippets Awaited `instance.database()` calls in async snippets to avoid AttributeError. --- .../samples/samples/async_snippets.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/google-cloud-spanner/samples/samples/async_snippets.py b/packages/google-cloud-spanner/samples/samples/async_snippets.py index c4cd0b258a12..99545b2067b4 100644 --- a/packages/google-cloud-spanner/samples/samples/async_snippets.py +++ b/packages/google-cloud-spanner/samples/samples/async_snippets.py @@ -26,7 +26,7 @@ async def async_create_client(instance_id, database_id): """Instantiates an asynchronous Spanner client.""" spanner_client = AsyncClient() instance = spanner_client.instance(instance_id) - database = instance.database(database_id) + database = await instance.database(database_id) print("Async Spanner client instantiated successfully.") return database @@ -40,7 +40,7 @@ async def async_query_data(instance_id, database_id): """Queries sample data from the database using asynchronous SQL.""" spanner_client = AsyncClient() instance = spanner_client.instance(instance_id) - database = instance.database(database_id) + database = await instance.database(database_id) async with database.snapshot() as snapshot: results = await snapshot.execute_sql( @@ -59,7 +59,7 @@ async def async_insert_data(instance_id, database_id): """Inserts sample data into the database using DML asynchronously.""" spanner_client = AsyncClient() instance = spanner_client.instance(instance_id) - database = instance.database(database_id) + database = await instance.database(database_id) async def insert_singers(transaction): dml = ( @@ -81,7 +81,7 @@ async def async_read_write_transaction(instance_id, database_id): """Performs an asynchronous read-write transaction.""" spanner_client = AsyncClient() instance = spanner_client.instance(instance_id) - database = instance.database(database_id) + database = await instance.database(database_id) async def update_singer_lastname(transaction): # Retrieve current name @@ -110,7 +110,7 @@ async def async_read_only_transaction(instance_id, database_id): """Performs an asynchronous read-only transaction.""" spanner_client = AsyncClient() instance = spanner_client.instance(instance_id) - database = instance.database(database_id) + database = await instance.database(database_id) async with database.snapshot() as snapshot: # Execute a read using standard KeySet