Skip to content

Commit a9651b1

Browse files
simorenohannatischgahl-levytjprescott
authored
[Cosmos] post-archboard fixes (Azure#24358)
* initial commit * Client Constructor (Azure#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 * get_authorization_header * remove __aenter__ Co-authored-by: annatisch <[email protected]> Co-authored-by: Gahl Levy <[email protected]> Co-authored-by: Travis Prescott <[email protected]>
1 parent 32e146b commit a9651b1

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

sdk/cosmos/azure-cosmos/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ For more information on TTL, see [Time to Live for Azure Cosmos DB data][cosmos_
468468
### Using the asynchronous client (Preview)
469469

470470
The asynchronous cosmos client is a separate client that looks and works in a similar fashion to the existing synchronous client. However, the async client needs to be imported separately and its methods need to be used with the async/await keywords.
471-
The Async client needs to be initialized and closed after usage. The example below shows how to do so by using the client's __aenter__() and close() methods.
471+
The Async client needs to be initialized and closed after usage, which can be done manually or with the use of a context manager. The example below shows how to do so manually.
472472

473473
```Python
474474
from azure.cosmos.aio import CosmosClient
@@ -481,7 +481,6 @@ CONTAINER_NAME = 'products'
481481

482482
async def create_products():
483483
client = CosmosClient(URL, credential=KEY)
484-
await client.__aenter__()
485484
database = client.get_database_client(DATABASE_NAME)
486485
container = database.get_container_client(CONTAINER_NAME)
487486
for i in range(10):

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
242242
headers[http_constants.HttpHeaders.XDate] = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
243243

244244
if cosmos_client_connection.master_key or cosmos_client_connection.resource_tokens:
245-
authorization = auth.get_authorization_header(
245+
authorization = auth._get_authorization_header(
246246
cosmos_client_connection, verb, path, resource_id, IsNameBased(resource_id), resource_type, headers
247247
)
248248
# urllib.quote throws when the input parameter is None

sdk/cosmos/azure-cosmos/azure/cosmos/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def GetAuthorizationHeader(
3636
warnings.warn("This method has been deprecated and will be removed from the SDK in a future release.",
3737
DeprecationWarning)
3838

39-
return get_authorization_header(
39+
return _get_authorization_header(
4040
cosmos_client_connection, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers)
4141

4242

43-
def get_authorization_header(
43+
def _get_authorization_header(
4444
cosmos_client_connection, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers
4545
):
4646
"""Gets the authorization header.

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@ async def examples_async():
1919
# which can only be used within async methods like examples_async() here
2020

2121
# Since this is an asynchronous client, in order to properly use it you also have to warm it up and close it down.
22-
# One way to do it would be like below (all of these statements would be necessary if you want to do it this way).
23-
24-
async_client = CosmosClient(url, key)
25-
await async_client.__aenter__()
26-
27-
# [CODE LOGIC HERE, CLOSING WITH THE STATEMENT BELOW WHEN DONE]
28-
29-
await async_client.close()
30-
31-
# Or better, you can use the `async with` keywords like below to start your clients - these keywords
22+
# We recommend using the `async with` keywords like below to start your clients - these keywords
3223
# create a context manager that automatically warms up, initializes, and cleans up the client, so you don't have to.
3324

3425
# [START create_client]

0 commit comments

Comments
 (0)