Skip to content

Commit

Permalink
bets practices recommends using string partition keys
Browse files Browse the repository at this point in the history
  • Loading branch information
simorenoh committed Apr 20, 2022
1 parent eeceef2 commit d44502f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
29 changes: 12 additions & 17 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ async def create_item(
async def read_item(
self,
item: Union[str, Dict[str, Any]],
partition_key: Union[str, int, float, bool],
partition_key: str,
**kwargs: Any
) -> Dict[str, Any]:
"""Get the item identified by `item`.
:param item: The ID (name) or dict representing item to retrieve.
:type item: Union[str, Dict[str, Any]]
:param partition_key: Partition key for the item to retrieve.
:type partition_key: Union[str, int, float, bool]
:param str partition_key: Partition key for the item to retrieve.
:keyword str session_token: Token for use with Session consistency.
:keyword Dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword response_hook: A callable invoked with the response metadata.
Expand Down Expand Up @@ -314,7 +314,7 @@ def query_items(
Each parameter is a dict() with 'name' and 'value' keys.
Ignored if no query is provided.
:type parameters: Optional[List[Dict[str, Any]]]
:param partition_key: Specifies the partition key value for the item. If none is provided,
:param str partition_key: Specifies the partition key value for the item. If none is provided,
a cross-partition query will be executed.
:type partition_key: Optional[Union[str, int, float, bool]]
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
Expand Down Expand Up @@ -400,8 +400,7 @@ def query_items_change_feed(
beginning (true) or from current (false). By default it's start from current (false).
:keyword str continuation: e_tag value to be used as continuation for reading change feed.
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
:keyword partition_key: partition key at which ChangeFeed requests are targeted.
:paramtype partition_key: Union[str, int, float, bool]
:keyword str partition_key: partition key at which ChangeFeed requests are targeted.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], Any]
:returns: An AsyncItemPaged of items (dicts).
Expand Down Expand Up @@ -531,7 +530,7 @@ async def replace_item(
async def delete_item(
self,
item: Union[str, Dict[str, Any]],
partition_key: Union[str, int, float, bool],
partition_key: str,
**kwargs: Any
) -> None:
"""Delete the specified item from the container.
Expand All @@ -540,8 +539,7 @@ async def delete_item(
:param item: The ID (name) or dict representing item to be deleted.
:type item: Union[str, Dict[str, Any]]
:param partition_key: Specifies the partition key value for the item.
:type partition_key: Union[str, int, float, bool]
:param str partition_key: Specifies the partition key value for the item.
:keyword str pre_trigger_include: trigger id to be used as pre operation trigger.
:keyword str post_trigger_include: trigger id to be used as post operation trigger.
:keyword str session_token: Token for use with Session consistency.
Expand Down Expand Up @@ -673,9 +671,8 @@ def query_conflicts(
:param str query: The Azure Cosmos DB SQL query to execute.
:param parameters: Optional array of parameters to the query. Ignored if no query is provided.
:type parameters: Optional[List[Dict[str, Any]]]
:param partition_key: Specifies the partition key value for the item. If none is passed in, a
:param str partition_key: Specifies the partition key value for the item. If none is passed in, a
cross partition query will be executed.
:type partition_key: Union[str, int, float, bool]
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], Any]
Expand Down Expand Up @@ -706,15 +703,14 @@ def query_conflicts(
async def read_conflict(
self,
conflict: Union[str, Dict[str, Any]],
partition_key: Union[str, int, float, bool],
partition_key: str,
**kwargs: Any,
) -> Dict[str, Any]:
"""Get the conflict identified by `conflict`.
:param conflict: The ID (name) or dict representing the conflict to retrieve.
:type conflict: Union[str, Dict[str, Any]]
:param partition_key: Partition key for the conflict to retrieve.
:type partition_key: Union[str, int, float, bool]
:param str partition_key: Partition key for the conflict to retrieve.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given conflict couldn't be retrieved.
Expand All @@ -735,7 +731,7 @@ async def read_conflict(
async def delete_conflict(
self,
conflict: Union[str, Dict[str, Any]],
partition_key: Union[str, int, float, bool],
partition_key: str,
**kwargs: Any,
) -> None:
"""Delete a specified conflict from the container.
Expand All @@ -744,8 +740,7 @@ async def delete_conflict(
:param conflict: The ID (name) or dict representing the conflict to retrieve.
:type conflict: Union[str, Dict[str, Any]]
:param partition_key: Partition key for the conflict to retrieve.
:type partition_key: Union[str, int, float, bool]
:param str partition_key: Partition key for the conflict to retrieve.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], None], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The conflict wasn't deleted successfully.
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def query_containers(
async def replace_container(
self,
container: Union[str, ContainerProxy, Dict[str, Any]],
partition_key: Union[str, int, float, bool],
partition_key: PartitionKey,
**kwargs: Any
) -> ContainerProxy:
"""Reset the properties of the container.
Expand All @@ -422,7 +422,7 @@ async def replace_container(
:class:`ContainerProxy` instance of the container to be replaced.
:type container: Union[str, Dict[str, Any], ~azure.cosmos.aio.ContainerProxy]
:param partition_key: The partition key to use for the container.
:type partition_key: Union[str, int, float, bool]
:type partition_key: ~azure.cosmos.partition_key.PartitionKey
:keyword Dict[str, str] indexing_policy: The indexing policy to apply to the container.
:keyword int default_ttl: Default time to live (TTL) for items in the container.
If unspecified, items do not expire.
Expand Down
5 changes: 2 additions & 3 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async def delete_stored_procedure(self, sproc: Union[str, Dict[str, Any]], **kwa
async def execute_stored_procedure(
self,
sproc: Union[str, Dict[str, Any]],
partition_key: Optional[Union[str, int, float, bool]] = None,
partition_key: Optional[str] = None,
params: Optional[List[Dict[str, Any]]] = None,
**kwargs: Any
) -> Dict[str, Any]:
Expand All @@ -207,9 +207,8 @@ async def execute_stored_procedure(
:param sproc: The ID (name) or dict representing the stored procedure to be executed.
:type sproc: Union[str, Dict[str, Any]]
:param partition_key: Specifies the partition key to indicate which partition the stored procedure should
:param Optional[str] partition_key: Specifies the partition key to indicate which partition the stored procedure should
execute on.
:type partition_key: Optional[Union[str, int, float, bool]]
:param params: List of parameters to be passed to the stored procedure to be executed.
:type params: Optional[List[Dict[str, Any]]]
:keyword bool enable_script_logging: Enables or disables script logging for the current request.
Expand Down

0 comments on commit d44502f

Please sign in to comment.