Skip to content

Commit d44502f

Browse files
committed
bets practices recommends using string partition keys
1 parent eeceef2 commit d44502f

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ async def create_item(
210210
async def read_item(
211211
self,
212212
item: Union[str, Dict[str, Any]],
213-
partition_key: Union[str, int, float, bool],
213+
partition_key: str,
214214
**kwargs: Any
215215
) -> Dict[str, Any]:
216216
"""Get the item identified by `item`.
217217
218218
:param item: The ID (name) or dict representing item to retrieve.
219219
:type item: Union[str, Dict[str, Any]]
220-
:param partition_key: Partition key for the item to retrieve.
221-
:type partition_key: Union[str, int, float, bool]
220+
:param str partition_key: Partition key for the item to retrieve.
221+
222222
:keyword str session_token: Token for use with Session consistency.
223223
:keyword Dict[str, str] initial_headers: Initial headers to be sent as part of the request.
224224
:keyword response_hook: A callable invoked with the response metadata.
@@ -314,7 +314,7 @@ def query_items(
314314
Each parameter is a dict() with 'name' and 'value' keys.
315315
Ignored if no query is provided.
316316
:type parameters: Optional[List[Dict[str, Any]]]
317-
:param partition_key: Specifies the partition key value for the item. If none is provided,
317+
:param str partition_key: Specifies the partition key value for the item. If none is provided,
318318
a cross-partition query will be executed.
319319
:type partition_key: Optional[Union[str, int, float, bool]]
320320
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
@@ -400,8 +400,7 @@ def query_items_change_feed(
400400
beginning (true) or from current (false). By default it's start from current (false).
401401
:keyword str continuation: e_tag value to be used as continuation for reading change feed.
402402
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
403-
:keyword partition_key: partition key at which ChangeFeed requests are targeted.
404-
:paramtype partition_key: Union[str, int, float, bool]
403+
:keyword str partition_key: partition key at which ChangeFeed requests are targeted.
405404
:keyword response_hook: A callable invoked with the response metadata.
406405
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], Any]
407406
:returns: An AsyncItemPaged of items (dicts).
@@ -531,7 +530,7 @@ async def replace_item(
531530
async def delete_item(
532531
self,
533532
item: Union[str, Dict[str, Any]],
534-
partition_key: Union[str, int, float, bool],
533+
partition_key: str,
535534
**kwargs: Any
536535
) -> None:
537536
"""Delete the specified item from the container.
@@ -540,8 +539,7 @@ async def delete_item(
540539
541540
:param item: The ID (name) or dict representing item to be deleted.
542541
:type item: Union[str, Dict[str, Any]]
543-
:param partition_key: Specifies the partition key value for the item.
544-
:type partition_key: Union[str, int, float, bool]
542+
:param str partition_key: Specifies the partition key value for the item.
545543
:keyword str pre_trigger_include: trigger id to be used as pre operation trigger.
546544
:keyword str post_trigger_include: trigger id to be used as post operation trigger.
547545
:keyword str session_token: Token for use with Session consistency.
@@ -673,9 +671,8 @@ def query_conflicts(
673671
:param str query: The Azure Cosmos DB SQL query to execute.
674672
:param parameters: Optional array of parameters to the query. Ignored if no query is provided.
675673
:type parameters: Optional[List[Dict[str, Any]]]
676-
:param partition_key: Specifies the partition key value for the item. If none is passed in, a
674+
:param str partition_key: Specifies the partition key value for the item. If none is passed in, a
677675
cross partition query will be executed.
678-
:type partition_key: Union[str, int, float, bool]
679676
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
680677
:keyword response_hook: A callable invoked with the response metadata.
681678
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], Any]
@@ -706,15 +703,14 @@ def query_conflicts(
706703
async def read_conflict(
707704
self,
708705
conflict: Union[str, Dict[str, Any]],
709-
partition_key: Union[str, int, float, bool],
706+
partition_key: str,
710707
**kwargs: Any,
711708
) -> Dict[str, Any]:
712709
"""Get the conflict identified by `conflict`.
713710
714711
:param conflict: The ID (name) or dict representing the conflict to retrieve.
715712
:type conflict: Union[str, Dict[str, Any]]
716-
:param partition_key: Partition key for the conflict to retrieve.
717-
:type partition_key: Union[str, int, float, bool]
713+
:param str partition_key: Partition key for the conflict to retrieve.
718714
:keyword response_hook: A callable invoked with the response metadata.
719715
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
720716
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given conflict couldn't be retrieved.
@@ -735,7 +731,7 @@ async def read_conflict(
735731
async def delete_conflict(
736732
self,
737733
conflict: Union[str, Dict[str, Any]],
738-
partition_key: Union[str, int, float, bool],
734+
partition_key: str,
739735
**kwargs: Any,
740736
) -> None:
741737
"""Delete a specified conflict from the container.
@@ -744,8 +740,7 @@ async def delete_conflict(
744740
745741
:param conflict: The ID (name) or dict representing the conflict to retrieve.
746742
:type conflict: Union[str, Dict[str, Any]]
747-
:param partition_key: Partition key for the conflict to retrieve.
748-
:type partition_key: Union[str, int, float, bool]
743+
:param str partition_key: Partition key for the conflict to retrieve.
749744
:keyword response_hook: A callable invoked with the response metadata.
750745
:paramtype response_hook: Callable[[Dict[str, str], None], Any]
751746
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The conflict wasn't deleted successfully.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def query_containers(
410410
async def replace_container(
411411
self,
412412
container: Union[str, ContainerProxy, Dict[str, Any]],
413-
partition_key: Union[str, int, float, bool],
413+
partition_key: PartitionKey,
414414
**kwargs: Any
415415
) -> ContainerProxy:
416416
"""Reset the properties of the container.
@@ -422,7 +422,7 @@ async def replace_container(
422422
:class:`ContainerProxy` instance of the container to be replaced.
423423
:type container: Union[str, Dict[str, Any], ~azure.cosmos.aio.ContainerProxy]
424424
:param partition_key: The partition key to use for the container.
425-
:type partition_key: Union[str, int, float, bool]
425+
:type partition_key: ~azure.cosmos.partition_key.PartitionKey
426426
:keyword Dict[str, str] indexing_policy: The indexing policy to apply to the container.
427427
:keyword int default_ttl: Default time to live (TTL) for items in the container.
428428
If unspecified, items do not expire.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async def delete_stored_procedure(self, sproc: Union[str, Dict[str, Any]], **kwa
197197
async def execute_stored_procedure(
198198
self,
199199
sproc: Union[str, Dict[str, Any]],
200-
partition_key: Optional[Union[str, int, float, bool]] = None,
200+
partition_key: Optional[str] = None,
201201
params: Optional[List[Dict[str, Any]]] = None,
202202
**kwargs: Any
203203
) -> Dict[str, Any]:
@@ -207,9 +207,8 @@ async def execute_stored_procedure(
207207
208208
:param sproc: The ID (name) or dict representing the stored procedure to be executed.
209209
:type sproc: Union[str, Dict[str, Any]]
210-
:param partition_key: Specifies the partition key to indicate which partition the stored procedure should
210+
:param Optional[str] partition_key: Specifies the partition key to indicate which partition the stored procedure should
211211
execute on.
212-
:type partition_key: Optional[Union[str, int, float, bool]]
213212
:param params: List of parameters to be passed to the stored procedure to be executed.
214213
:type params: Optional[List[Dict[str, Any]]]
215214
:keyword bool enable_script_logging: Enables or disables script logging for the current request.

0 commit comments

Comments
 (0)