Skip to content

Commit adf7d27

Browse files
test(spanner): await database calls in async snippets (#17627)
Awaited `instance.database()` calls in async snippets to avoid AttributeError. Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-cloud-python/issues) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 247e2ad commit adf7d27

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

packages/google-cloud-spanner/samples/samples/async_snippets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def async_create_client(instance_id, database_id):
2626
"""Instantiates an asynchronous Spanner client."""
2727
spanner_client = AsyncClient()
2828
instance = spanner_client.instance(instance_id)
29-
database = instance.database(database_id)
29+
database = await instance.database(database_id)
3030

3131
print("Async Spanner client instantiated successfully.")
3232
return database
@@ -40,7 +40,7 @@ async def async_query_data(instance_id, database_id):
4040
"""Queries sample data from the database using asynchronous SQL."""
4141
spanner_client = AsyncClient()
4242
instance = spanner_client.instance(instance_id)
43-
database = instance.database(database_id)
43+
database = await instance.database(database_id)
4444

4545
async with database.snapshot() as snapshot:
4646
results = await snapshot.execute_sql(
@@ -59,7 +59,7 @@ async def async_insert_data(instance_id, database_id):
5959
"""Inserts sample data into the database using DML asynchronously."""
6060
spanner_client = AsyncClient()
6161
instance = spanner_client.instance(instance_id)
62-
database = instance.database(database_id)
62+
database = await instance.database(database_id)
6363

6464
async def insert_singers(transaction):
6565
dml = (
@@ -81,7 +81,7 @@ async def async_read_write_transaction(instance_id, database_id):
8181
"""Performs an asynchronous read-write transaction."""
8282
spanner_client = AsyncClient()
8383
instance = spanner_client.instance(instance_id)
84-
database = instance.database(database_id)
84+
database = await instance.database(database_id)
8585

8686
async def update_singer_lastname(transaction):
8787
# Retrieve current name
@@ -110,7 +110,7 @@ async def async_read_only_transaction(instance_id, database_id):
110110
"""Performs an asynchronous read-only transaction."""
111111
spanner_client = AsyncClient()
112112
instance = spanner_client.instance(instance_id)
113-
database = instance.database(database_id)
113+
database = await instance.database(database_id)
114114

115115
async with database.snapshot() as snapshot:
116116
# Execute a read using standard KeySet

0 commit comments

Comments
 (0)