Skip to content

Commit bf7e0d2

Browse files
simorenohannatischgahl-levytjprescott
authored andcommitted
[Cosmos] Improve system key computation logic (Azure#23821)
* 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 * Update cosmos_client.py * Update container.py * Update container.py * changelog Co-authored-by: annatisch <[email protected]> Co-authored-by: Gahl Levy <[email protected]> Co-authored-by: Travis Prescott <[email protected]>
1 parent a7c379a commit bf7e0d2

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
### 4.3.0b4 (Unreleased)
44

55
#### Features Added
6-
- Added support for AAD authentication for the async client
7-
- Added support for AAD authentication for the sync client
6+
- Added support for AAD authentication for the async client.
7+
- Added support for AAD authentication for the sync client.
8+
9+
#### Other Changes
10+
- Changed `_set_partition_key` return typehint in async client.
811

912
### 4.3.0b3 (2022-03-10)
1013

sdk/cosmos/azure-cosmos/azure/cosmos/aio/container.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""Create, read, update and delete items in the Azure Cosmos DB SQL API service.
2323
"""
2424

25-
from typing import Any, Dict, List, Optional, Union, cast
25+
from typing import Any, Dict, List, Optional, Union, cast, Awaitable
2626
from azure.core.async_paging import AsyncItemPaged
2727

2828
from azure.core.tracing.decorator import distributed_trace # pylint: disable=unused-import
@@ -106,11 +106,12 @@ def _get_conflict_link(self, conflict_or_link):
106106
return u"{}/conflicts/{}".format(self.container_link, conflict_or_link)
107107
return conflict_or_link["_self"]
108108

109-
async def _set_partition_key(self, partition_key):
109+
def _set_partition_key(self, partition_key) -> Union[str, Awaitable]:
110110
if partition_key == NonePartitionKeyValue:
111-
return CosmosClientConnection._return_undefined_or_empty_partition_key(await self.is_system_key)
111+
return CosmosClientConnection._return_undefined_or_empty_partition_key(self.is_system_key)
112112
return partition_key
113113

114+
114115
@distributed_trace_async
115116
async def read(
116117
self,
@@ -231,8 +232,7 @@ async def read_item(
231232
doc_link = self._get_document_link(item)
232233
request_options = _build_options(kwargs)
233234
response_hook = kwargs.pop('response_hook', None)
234-
if partition_key is not None:
235-
request_options["partitionKey"] = await self._set_partition_key(partition_key)
235+
request_options["partitionKey"] = self._set_partition_key(partition_key)
236236
max_integrated_cache_staleness_in_ms = kwargs.pop('max_integrated_cache_staleness_in_ms', None)
237237
if max_integrated_cache_staleness_in_ms is not None:
238238
validate_cache_staleness_value(max_integrated_cache_staleness_in_ms)
@@ -399,7 +399,7 @@ def query_items_change_feed(
399399
feed_options["partitionKeyRangeId"] = partition_key_range_id
400400
partition_key = kwargs.pop("partitionKey", None)
401401
if partition_key is not None:
402-
feed_options["partitionKey"] = partition_key
402+
feed_options["partitionKey"] = self._set_partition_key(partition_key)
403403
if is_start_from_beginning is not None:
404404
feed_options["isStartFromBeginning"] = is_start_from_beginning
405405
if max_item_count is not None:
@@ -534,8 +534,7 @@ async def delete_item(
534534
"""
535535
request_options = _build_options(kwargs)
536536
response_hook = kwargs.pop('response_hook', None)
537-
if partition_key is not None:
538-
request_options["partitionKey"] = await self._set_partition_key(partition_key)
537+
request_options["partitionKey"] = self._set_partition_key(partition_key)
539538
if pre_trigger_include is not None:
540539
request_options["preTriggerInclude"] = pre_trigger_include
541540
if post_trigger_include is not None:
@@ -691,9 +690,7 @@ async def read_conflict(
691690
"""
692691
request_options = _build_options(kwargs)
693692
response_hook = kwargs.pop('response_hook', None)
694-
if partition_key is not None:
695-
request_options["partitionKey"] = await self._set_partition_key(partition_key)
696-
693+
request_options["partitionKey"] = self._set_partition_key(partition_key)
697694
result = await self.client_connection.ReadConflict(
698695
conflict_link=self._get_conflict_link(conflict), options=request_options, **kwargs
699696
)
@@ -721,9 +718,7 @@ async def delete_conflict(
721718
"""
722719
request_options = _build_options(kwargs)
723720
response_hook = kwargs.pop('response_hook', None)
724-
if partition_key is not None:
725-
request_options["partitionKey"] = await self._set_partition_key(partition_key)
726-
721+
request_options["partitionKey"] = self._set_partition_key(partition_key)
727722
result = await self.client_connection.DeleteConflict(
728723
conflict_link=self._get_conflict_link(conflict), options=request_options, **kwargs
729724
)

sdk/cosmos/azure-cosmos/azure/cosmos/partition_key.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"""Create partition keys in the Azure Cosmos DB SQL API service.
2323
"""
2424

25+
2526
class NonePartitionKeyValue(object):
2627
"""Represents None value for partitionKey when it's missing in a container.
2728
"""

0 commit comments

Comments
 (0)