From 9f86899c1bf3b0c02e86b52518c21496e0117660 Mon Sep 17 00:00:00 2001 From: Simon Moreno <30335873+simorenoh@users.noreply.github.com> Date: Wed, 19 Jan 2022 10:52:14 -0500 Subject: [PATCH] [Cosmos] update from_connection_string method (#22536) * initial commit * Client Constructor (#20310) * Removed some stuff * Looking at constructors * Updated request * Added client close * working client creation Co-authored-by: simorenoh * 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 <75269480+gahl-levy@users.noreply.github.com> * closing python code snippet * last doc updates * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com> * version update * cosmos updates for release * fix connection string comma * Update CHANGELOG.md Co-authored-by: annatisch Co-authored-by: Gahl Levy <75269480+gahl-levy@users.noreply.github.com> Co-authored-by: Travis Prescott --- sdk/cosmos/azure-cosmos/CHANGELOG.md | 8 -------- .../azure/cosmos/aio/cosmos_client.py | 17 ++++++++++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/CHANGELOG.md b/sdk/cosmos/azure-cosmos/CHANGELOG.md index c23eab47fee8..492651653776 100644 --- a/sdk/cosmos/azure-cosmos/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos/CHANGELOG.md @@ -5,14 +5,6 @@ This version and all future versions will require Python 3.6+. Python 2.7 is no longer supported. We will also be removing support for Python 3.6 and will only support Python 3.7+ starting December 2022. -#### Features Added - -#### Breaking Changes - -#### Bugs Fixed - -#### Other Changes - ### 4.3.0b1 (2021-12-14) **New features** - Added language native async i/o client diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/aio/cosmos_client.py b/sdk/cosmos/azure-cosmos/azure/cosmos/aio/cosmos_client.py index 2ada4a8d0388..f46e7f1aa620 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/aio/cosmos_client.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/aio/cosmos_client.py @@ -141,25 +141,28 @@ async def close(self): await self.__aexit__() @classmethod - def from_connection_string(cls, conn_str, credential=None, **kwargs): - # type: (str, Optional[Any], str, Any) -> CosmosClient + def from_connection_string(cls, conn_str, credential=None, consistency_level="Session", **kwargs): + # type: (str, Optional[Union[str, Dict[str, str]]], str, Any) -> CosmosClient """Create a CosmosClient instance from a connection string. This can be retrieved from the Azure portal.For full list of optional keyword arguments, see the CosmosClient constructor. - :param str conn_str: The connection string. + :param conn_str: The connection string. + :type conn_str: str :param credential: Alternative credentials to use instead of the key provided in the connection string. - :type credential: str or dict(str, str) - :keyword str consistency_level: - Consistency level to use for the session. The default value is "Session". + :type credential: str or Dict[str, str] + :param conn_str: The connection string. + :type conn_str: str + :param consistency_level: Consistency level to use for the session. The default value is "Session". + :type consistency_level: str """ settings = _parse_connection_str(conn_str, credential) return cls( url=settings['AccountEndpoint'], credential=credential or settings['AccountKey'], - consistency_level=kwargs.get('consistency_level', 'Session') + consistency_level=consistency_level, **kwargs )