Skip to content

Commit fa0f63f

Browse files
simorenohannatischgahl-levytjprescott
authored
[Cosmos ] Fix async end-to-end example (#23653)
* initial commit * Client Constructor (#20310) * Removed some stuff * Looking at constructors * Updated request * Added client close * working client creation Co-authored-by: simorenoh <[email protected]> * read database database read works, but ignored exception is returned: Fatal error on SSL transport NoneType has no attribute 'send' (_loop._proactor.send) RuntimeError: Event loop is closed Unclosed connector/ connection * Update simon_testfile.py * with coroutine Added methods needed to use async with when initializing client, but logs output "Exception ignored... Runtime Error: Event loop is closed" * Update simon_testfile.py * small changes * async with returns no exceptions * async read container * async item read * cleaning up * create item/ database methods * item delete working * docs replace functionality missing upsert and other resources * upsert functionality missing read_all_items and both query methods for container class * missing query methods * CRUD for udf, sproc, triggers * initial query logic + container methods * missing some execution logic and tests * oops * fully working queries * small fix to query_items() also fixed README and added examples_async * Update _cosmos_client_connection_async.py * Update _cosmos_client_connection.py * documentation update * updated MIT dates and get_user_client() description * Update CHANGELOG.md * Delete simon_testfile.py * leftover retry utility * Update README.md * docs and removed six package * changes based on comments still missing discussion resolution on SSL verification and tests for async functionality under test module (apart from samples which are basically end to end tests) * small change in type hints * updated readme * fixes based on conversations * added missing type comments * update changelog for ci pipeline * added typehints, moved params into keywords, added decorators, made _connection_policy private * changes based on sync with central sdk * remove is_system_key from scripts (only used in execute_sproc) is_system_key verifies that an empty partition key is properly dealt with if ['partitionKey']['systemKey'] exists in the container options - however, we do not allow containers to be created with empty partition key values in the python sdk, so the functionality is needless * Revert "remove is_system_key from scripts (only used in execute_sproc)" Reverting last commit, will find way to init is_system_key for now * async script proxy using composition * pylint * capitalized constants * Apply suggestions from code review Clarifying comments for README Co-authored-by: Gahl Levy <[email protected]> * closing python code snippet * last doc updates * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Simon Moreno <[email protected]> * version update * cosmos updates for release * fix connection string comma * Update CHANGELOG.md * fixing extra await keyword in sample * Update CHANGELOG.md * Update CHANGELOG.md * few blips that were missed in translation Co-authored-by: annatisch <[email protected]> Co-authored-by: Gahl Levy <[email protected]> Co-authored-by: Travis Prescott <[email protected]>
1 parent afa2354 commit fa0f63f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sdk/cosmos/azure-cosmos/samples/examples_async.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
from azure.cosmos import exceptions, CosmosClient, PartitionKey
23
from azure.cosmos.aio import CosmosClient
34

@@ -37,7 +38,7 @@ async def examples_async():
3738
try:
3839
database = await client.create_database(id=database_name)
3940
except exceptions.CosmosResourceExistsError:
40-
database = client.get_database_client(database_id=database_name)
41+
database = client.get_database_client(database=database_name)
4142
# [END create_database]
4243

4344
# Create a container, handling the exception if a container with the
@@ -76,7 +77,7 @@ async def examples_async():
7677

7778
# [START list_containers]
7879
database = client.get_database_client(database_name)
79-
for container in database.list_containers():
80+
async for container in database.list_containers():
8081
print("Container ID: {}".format(container['id']))
8182
# [END list_containers]
8283

@@ -155,8 +156,16 @@ async def examples_async():
155156
# [START create_user]
156157
try:
157158
await database.create_user(dict(id="Walter Harp"))
159+
print("Created user Walter Harp.")
158160
except exceptions.CosmosResourceExistsError:
159161
print("A user with that ID already exists.")
160162
except exceptions.CosmosHttpResponseError as failure:
161163
print("Failed to create user. Status code:{}".format(failure.status_code))
162164
# [END create_user]
165+
166+
await client.delete_database(database_name)
167+
print("Sample done running!")
168+
169+
if __name__ == "__main__":
170+
loop = asyncio.get_event_loop()
171+
loop.run_until_complete(examples_async())

0 commit comments

Comments
 (0)