|
22 | 22 | """Create, read, update and delete items in the Azure Cosmos DB SQL API service.
|
23 | 23 | """
|
24 | 24 |
|
25 |
| -from typing import Any, Dict, List, Optional, Union, cast |
| 25 | +from typing import Any, Dict, List, Optional, Union, cast, Awaitable |
26 | 26 | from azure.core.async_paging import AsyncItemPaged
|
27 | 27 |
|
28 | 28 | from azure.core.tracing.decorator import distributed_trace # pylint: disable=unused-import
|
@@ -106,11 +106,12 @@ def _get_conflict_link(self, conflict_or_link):
|
106 | 106 | return u"{}/conflicts/{}".format(self.container_link, conflict_or_link)
|
107 | 107 | return conflict_or_link["_self"]
|
108 | 108 |
|
109 |
| - async def _set_partition_key(self, partition_key): |
| 109 | + def _set_partition_key(self, partition_key) -> Union[str, Awaitable]: |
110 | 110 | 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) |
112 | 112 | return partition_key
|
113 | 113 |
|
| 114 | + |
114 | 115 | @distributed_trace_async
|
115 | 116 | async def read(
|
116 | 117 | self,
|
@@ -231,8 +232,7 @@ async def read_item(
|
231 | 232 | doc_link = self._get_document_link(item)
|
232 | 233 | request_options = _build_options(kwargs)
|
233 | 234 | 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) |
236 | 236 | max_integrated_cache_staleness_in_ms = kwargs.pop('max_integrated_cache_staleness_in_ms', None)
|
237 | 237 | if max_integrated_cache_staleness_in_ms is not None:
|
238 | 238 | validate_cache_staleness_value(max_integrated_cache_staleness_in_ms)
|
@@ -399,7 +399,7 @@ def query_items_change_feed(
|
399 | 399 | feed_options["partitionKeyRangeId"] = partition_key_range_id
|
400 | 400 | partition_key = kwargs.pop("partitionKey", None)
|
401 | 401 | if partition_key is not None:
|
402 |
| - feed_options["partitionKey"] = partition_key |
| 402 | + feed_options["partitionKey"] = self._set_partition_key(partition_key) |
403 | 403 | if is_start_from_beginning is not None:
|
404 | 404 | feed_options["isStartFromBeginning"] = is_start_from_beginning
|
405 | 405 | if max_item_count is not None:
|
@@ -534,8 +534,7 @@ async def delete_item(
|
534 | 534 | """
|
535 | 535 | request_options = _build_options(kwargs)
|
536 | 536 | 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) |
539 | 538 | if pre_trigger_include is not None:
|
540 | 539 | request_options["preTriggerInclude"] = pre_trigger_include
|
541 | 540 | if post_trigger_include is not None:
|
@@ -691,9 +690,7 @@ async def read_conflict(
|
691 | 690 | """
|
692 | 691 | request_options = _build_options(kwargs)
|
693 | 692 | 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) |
697 | 694 | result = await self.client_connection.ReadConflict(
|
698 | 695 | conflict_link=self._get_conflict_link(conflict), options=request_options, **kwargs
|
699 | 696 | )
|
@@ -721,9 +718,7 @@ async def delete_conflict(
|
721 | 718 | """
|
722 | 719 | request_options = _build_options(kwargs)
|
723 | 720 | 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) |
727 | 722 | result = await self.client_connection.DeleteConflict(
|
728 | 723 | conflict_link=self._get_conflict_link(conflict), options=request_options, **kwargs
|
729 | 724 | )
|
|
0 commit comments