Skip to content

Commit

Permalink
[Cosmos] post-archboard fixes (#24358)
Browse files Browse the repository at this point in the history
* 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

* 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]>
  • Loading branch information
4 people authored May 11, 2022
1 parent a80bbdd commit 7b20eb6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
3 changes: 1 addition & 2 deletions sdk/cosmos/azure-cosmos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ For more information on TTL, see [Time to Live for Azure Cosmos DB data][cosmos_
### Using the asynchronous client (Preview)

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.
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.
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.

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

async def create_products():
client = CosmosClient(URL, credential=KEY)
await client.__aenter__()
database = client.get_database_client(DATABASE_NAME)
container = database.get_container_client(CONTAINER_NAME)
for i in range(10):
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/azure/cosmos/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
headers[http_constants.HttpHeaders.XDate] = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")

if cosmos_client_connection.master_key or cosmos_client_connection.resource_tokens:
authorization = auth.get_authorization_header(
authorization = auth._get_authorization_header(
cosmos_client_connection, verb, path, resource_id, IsNameBased(resource_id), resource_type, headers
)
# urllib.quote throws when the input parameter is None
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure-cosmos/azure/cosmos/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def GetAuthorizationHeader(
warnings.warn("This method has been deprecated and will be removed from the SDK in a future release.",
DeprecationWarning)

return get_authorization_header(
return _get_authorization_header(
cosmos_client_connection, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers)


def get_authorization_header(
def _get_authorization_header(
cosmos_client_connection, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers
):
"""Gets the authorization header.
Expand Down
11 changes: 1 addition & 10 deletions sdk/cosmos/azure-cosmos/samples/examples_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ async def examples_async():
# which can only be used within async methods like examples_async() here

# Since this is an asynchronous client, in order to properly use it you also have to warm it up and close it down.
# One way to do it would be like below (all of these statements would be necessary if you want to do it this way).

async_client = CosmosClient(url, key)
await async_client.__aenter__()

# [CODE LOGIC HERE, CLOSING WITH THE STATEMENT BELOW WHEN DONE]

await async_client.close()

# Or better, you can use the `async with` keywords like below to start your clients - these keywords
# We recommend using the `async with` keywords like below to start your clients - these keywords
# create a context manager that automatically warms up, initializes, and cleans up the client, so you don't have to.

# [START create_client]
Expand Down

0 comments on commit 7b20eb6

Please sign in to comment.