From 45da05716817a2be5429f7a6d7f20144d1cde2cb Mon Sep 17 00:00:00 2001 From: antisch Date: Tue, 29 Oct 2019 13:36:56 -0700 Subject: [PATCH 01/12] Made version file internal --- sdk/cosmos/azure-cosmos/azure/cosmos/__init__.py | 2 +- sdk/cosmos/azure-cosmos/azure/cosmos/_utils.py | 2 +- .../azure-cosmos/azure/cosmos/{version.py => _version.py} | 0 sdk/cosmos/azure-cosmos/setup.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename sdk/cosmos/azure-cosmos/azure/cosmos/{version.py => _version.py} (100%) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/__init__.py b/sdk/cosmos/azure-cosmos/azure/cosmos/__init__.py index 1f73d170e3c4..406418f1e0cc 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/__init__.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/__init__.py @@ -19,6 +19,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from ._version import VERSION from ._retry_utility import ConnectionRetryPolicy from .container import ContainerProxy from .cosmos_client import CosmosClient @@ -40,7 +41,6 @@ ) from .partition_key import PartitionKey from .permission import Permission -from .version import VERSION __all__ = ( "CosmosClient", diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_utils.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_utils.py index f44e3a906bda..b6b6f0e18d4a 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_utils.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_utils.py @@ -24,7 +24,7 @@ import platform import re -from .version import VERSION +from ._version import VERSION def get_user_agent(): diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/version.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_version.py similarity index 100% rename from sdk/cosmos/azure-cosmos/azure/cosmos/version.py rename to sdk/cosmos/azure-cosmos/azure/cosmos/_version.py diff --git a/sdk/cosmos/azure-cosmos/setup.py b/sdk/cosmos/azure-cosmos/setup.py index afe2cb0786fb..a0aae6f28deb 100644 --- a/sdk/cosmos/azure-cosmos/setup.py +++ b/sdk/cosmos/azure-cosmos/setup.py @@ -21,7 +21,7 @@ NAMESPACE_NAME = PACKAGE_NAME.replace("-", ".") # Version extraction inspired from 'requests' -with open(os.path.join(PACKAGE_FOLDER_PATH, 'version.py'), 'r') as fd: +with open(os.path.join(PACKAGE_FOLDER_PATH, '_version.py'), 'r') as fd: version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) From 9ac1ce9d79f33b75d7d69aa2dbd89ee24999b0ff Mon Sep 17 00:00:00 2001 From: antisch Date: Tue, 29 Oct 2019 14:14:03 -0700 Subject: [PATCH 02/12] Updated kwargs --- sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | 6 +- .../azure/cosmos/cosmos_client.py | 120 +++++++----------- 2 files changed, 51 insertions(+), 75 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py index 41d9adab68e9..f67497cf6f6a 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py @@ -63,7 +63,11 @@ 'continuation': 'continuation', 'is_start_from_beginning': 'isStartFromBeginning', 'populate_partition_key_range_statistics': 'populatePartitionKeyRangeStatistics', - 'populate_quota_info': 'populateQuotaInfo' + 'populate_quota_info': 'populateQuotaInfo', + 'content_type': 'contentType', + 'is_query_plan_request': 'isQueryPlanRequest', + 'supported_query_features': 'supportedQueryFeatures', + 'query_version': 'queryVersion' } def build_options(kwargs): diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py index b00e46d0e7b3..ca69226fd0a7 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py @@ -126,53 +126,31 @@ class CosmosClient(object): Use this client to configure and execute requests to the Azure Cosmos DB service. :param str url: The URL of the Cosmos DB account. - :param credential: - Can be the account key, or a dictionary of resource tokens. + :param credential: Can be the account key, or a dictionary of resource tokens. :type credential: str or dict[str, str] - :param str consistency_level: - Consistency level to use for the session. The default value is "Session". - - **Keyword arguments:** - - *timeout* - An absolute timeout in seconds, for the combined HTTP request and response processing. - - *request_timeout* - The HTTP request timeout in seconds. - - *media_request_timeout* - The media request timeout in seconds. - - *connection_mode* - The connection mode for the client - currently only supports 'Gateway'. - - *media_read_mode* - The mode for use with downloading attachment content - default value is `Buffered`. - - *proxy_config* - Instance of `azure.cosmos.ProxyConfiguration`. - - *ssl_config* - Instance of `azure.cosmos.SSLConfiguration`. - - *connection_verify* - Whether to verify the connection, default value is True. - - *connection_cert* - An alternative certificate to verify the connection. - - *retry_total* - Maximum retry attempts. - - *retry_backoff_max* - Maximum retry wait time in seconds. - - *retry_fixed_interval* - Fixed retry interval in milliseconds. - - *retry_read* - Maximum number of socket read retry attempts. - - *retry_connect* - Maximum number of connection error retry attempts. - - *retry_status* - Maximum number of retry attempts on error status codes. - - *retry_on_status_codes* - A list of specific status codes to retry on. - - *retry_backoff_factor* - Factor to calculate wait time between retry attempts. - - *enable_endpoint_discovery* - Enable endpoint discovery for geo-replicated database accounts. Default is True. - - *preferred_locations* - The preferred locations for geo-replicated database accounts. - - *connection_policy* - An instance of `azure.cosmos.documents.ConnectionPolicy` + :param str consistency_level: Consistency level to use for the session. The default value is "Session". + :keyword int timeout: An absolute timeout in seconds, for the combined HTTP request and response processing. + :keyword int request_timeout: The HTTP request timeout in seconds. + :keyword int media_request_timeout: The media request timeout in seconds. + :keyword str connection_mode: The connection mode for the client - currently only supports 'Gateway'. + :keyword str media_read_mode: The mode for use with downloading attachment content - default value is `Buffered`. + :keyword proxy_config: Connection proxy configuration. + :paramtype proxy_config: ~azure.cosmos.ProxyConfiguration + :keyword ssl_config: Connection SSL configuration. + :paramtype ssl_config: ~azure.cosmos.SSLConfiguration + :keyword bool connection_verify: Whether to verify the connection, default value is True. + :keyword str connection_cert: An alternative certificate to verify the connection. + :keyword int retry_total: Maximum retry attempts. + :keyword int retry_backoff_max: Maximum retry wait time in seconds. + :keyword int retry_fixed_interval: Fixed retry interval in milliseconds. + :keyword int retry_read: Maximum number of socket read retry attempts. + :keyword int retry_connect: Maximum number of connection error retry attempts. + :keyword int retry_status: Maximum number of retry attempts on error status codes. + :keyword list[int] retry_on_status_codes: A list of specific status codes to retry on. + :keyword float retry_backoff_factor: Factor to calculate wait time between retry attempts. + :keyword bool enable_endpoint_discovery: Enable endpoint discovery for geo-replicated database accounts. + Default is True. + :keyword list[str] preferred_locations: The preferred locations for geo-replicated database accounts. .. admonition:: Example: @@ -252,6 +230,8 @@ def create_database( # pylint: disable=redefined-builtin """ Create a new database with the given ID (name). + See aka.ms/{} for a full list of optional request and feed keyword arguments. + :param id: ID (name) of the database to create. :param str session_token: Token for use with Session consistency. :param initial_headers: Initial headers to be sent as part of the request. @@ -260,9 +240,7 @@ def create_database( # pylint: disable=redefined-builtin :type access_condition: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. :param int offer_throughput: The provisioned throughput for this offer. - :param request_options: Dictionary of additional properties to be used for the request. - :type request_options: dict[str, Any] - :param Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A DatabaseProxy instance representing the new database. :rtype: ~azure.cosmos.DatabaseProxy :raises ~azure.cosmos.exceptions.CosmosResourceExistsError: Database with the given ID already exists. @@ -305,6 +283,7 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin If the database already exists, the existing settings are returned. Note: it does not check or update the existing database settings or offer throughput if they differ from what was passed into the method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of the database to read or create. :param str session_token: Token for use with Session consistency. @@ -314,9 +293,7 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin :type access_condition: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. :param int offer_throughput: The provisioned throughput for this offer. - :param request_options: Dictionary of additional properties to be used for the request. - :type request_options: dict[str, Any] - :param Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A DatabaseProxy instance representing the database. :rtype: ~azure.cosmos.DatabaseProxy :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The database read or creation failed. @@ -338,8 +315,7 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin def get_database_client(self, database): # type: (Union[str, DatabaseProxy, Dict[str, Any]]) -> DatabaseProxy - """ - Retrieve an existing database with the ID (name) `id`. + """Retrieve an existing database with the ID (name) `id`. :param database: The ID (name), dict representing the properties or `DatabaseProxy` instance of the database to read. @@ -364,17 +340,16 @@ def list_databases( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - List the databases in a Cosmos DB SQL database account. + """List the databases in a Cosmos DB SQL database account. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param int max_item_count: Max number of items to be returned in the enumeration operation. :param str session_token: Token for use with Session consistency. :param initial_headers: Initial headers to be sent as part of the request. :type initial_headers: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. - :param feed_options: Dictionary of additional properties to be used for the request. - :type feed_options: dict[str, str] - :param Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of database properties (dicts). :rtype: Iterable[dict[str, str]] """ @@ -404,18 +379,17 @@ def query_databases( """ Query the databases in a Cosmos DB SQL database account. + See aka.ms/{} for a full list of optional request and feed keyword arguments. + :param str query: The Azure Cosmos DB SQL query to execute. :param list[str] parameters: Optional array of parameters to the query. Ignored if no query is provided. :param bool enable_cross_partition_query: Allow scan on the queries which couldn't be served as indexing was opted out on the requested paths. :param int max_item_count: Max number of items to be returned in the enumeration operation. - :param str session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :type initial_headers: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. - :param feed_options: Dictionary of additional properties to be used for the request. - :type feed_options: dict[str, Any] - :param Callable response_hook: a callable invoked with the response metadata + :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 Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of database properties (dicts). :rtype: Iterable[dict[str, str]] """ @@ -453,18 +427,16 @@ def delete_database( """ Delete the database with the given ID (name). + See aka.ms/{} for a full list of optional request and feed keyword arguments. + :param database: The ID (name), dict representing the properties or :class:`DatabaseProxy` instance of the database to delete. :type database: str or dict(str, str) or ~azure.cosmos.DatabaseProxy - :param str session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :type initial_headers: dict[str, str] - :param access_condition: Conditions Associated with the request. - :type access_condition: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. - :param request_options: Dictionary of additional properties to be used for the request. - :type request_options: dict[str, Any] - :param Callable response_hook: a callable invoked with the response metadata + :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 dict[str,str] access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the database couldn't be deleted. :rtype: None """ @@ -484,7 +456,7 @@ def get_database_account(self, **kwargs): """ Retrieve the database account information. - :param Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `DatabaseAccount` instance representing the Cosmos DB Database Account. :rtype: ~azure.cosmos.DatabaseAccount """ From 108655259eb98883357185475c5690f09f1478aa Mon Sep 17 00:00:00 2001 From: antisch Date: Tue, 29 Oct 2019 14:57:54 -0700 Subject: [PATCH 03/12] Updated docstrings --- .../azure-cosmos/azure/cosmos/container.py | 155 +++++++++-------- .../azure-cosmos/azure/cosmos/database.py | 159 +++++++++--------- .../azure-cosmos/azure/cosmos/scripts.py | 113 +++++++------ sdk/cosmos/azure-cosmos/azure/cosmos/user.py | 66 ++++---- 4 files changed, 242 insertions(+), 251 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py index c1f1c2657057..8986db05266f 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py @@ -120,17 +120,17 @@ def read( **kwargs # type: Any ): # type: (...) -> Dict[str, Any] - """ - Read the container properties + """Read the container properties. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param populate_partition_key_range_statistics: Enable returning partition key range statistics in response headers. :param populate_quota_info: Enable returning collection storage quota information in response headers. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Raised if the container couldn't be retrieved. This includes if the container does not exist. :returns: Dict representing the retrieved container. @@ -165,17 +165,17 @@ def read_item( **kwargs # type: Any ): # type: (...) -> Dict[str, str] - """ - Get the item identified by `item`. + """Get the item identified by `item`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param item: The ID (name) or dict representing item to retrieve. :param partition_key: Partition key for the item to retrieve. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param post_trigger_include: trigger id to be used as post operation trigger. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :returns: Dict representing the item to be retrieved. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item couldn't be retrieved. :rtype: dict[str, Any] @@ -214,15 +214,15 @@ def read_all_items( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - List all items in the container. + """List all items in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param populate_query_metrics: Enable returning query metrics in response headers. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of items (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -253,8 +253,9 @@ def query_items_change_feed( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - Get a sorted list of items that were changed, in the order in which they were modified. + """Get a sorted list of items that were changed, in the order in which they were modified. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param partition_key_range_id: ChangeFeed requests can be executed against specific partition key ranges. This is used to process the change feed in parallel across multiple consumers. @@ -262,8 +263,7 @@ def query_items_change_feed( beginning (true) or from current (false). By default it's start from current (false). :param continuation: e_tag value to be used as continuation for reading change feed. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of items (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -301,12 +301,12 @@ def query_items( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - Return all results matching the given `query`. + """Return all results matching the given `query`. You can use any value for the container name in the FROM clause, but typically the container name is used. In the examples below, the container name is "products," and is aliased as "p" for easier referencing in the WHERE clause. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. @@ -315,13 +315,12 @@ def query_items( execute the query in the Azure Cosmos DB service. More than one request is necessary if the query is not scoped to single partition key value. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param enable_scan_in_query: Allow scan on the queries which couldn't be served as indexing was opted out on the requested paths. :param populate_query_metrics: Enable returning query metrics in response headers. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of items (dicts). :rtype: Iterable[dict[str, Any]] @@ -382,19 +381,19 @@ def replace_item( **kwargs # type: Any ): # type: (...) -> Dict[str, str] - """ - Replaces the specified item if it exists in the container. + """Replaces the specified item if it exists in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param item: The ID (name) or dict representing item to be replaced. :param body: A dict-like object representing the item to replace. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the item after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The replace failed or the item with given id does not exist. @@ -428,19 +427,19 @@ def upsert_item( **kwargs # type: Any ): # type: (...) -> Dict[str, str] - """ - Insert or update the specified item. + """Insert or update the specified item. + If the item already exists in the container, it is replaced. If it does not, it is inserted. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the item to update or insert. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the upserted item. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item could not be upserted. :rtype: dict[str, Any] @@ -472,20 +471,20 @@ def create_item( **kwargs # type: Any ): # type: (...) -> Dict[str, str] - """ - Create an item in the container. + """Create an item in the container. + To update or replace an existing item, use the :func:`ContainerProxy.upsert_item` method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the item to create. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. :param indexing_directive: Indicate whether the document should be omitted from indexing. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the new item. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Item with the given ID already exists. :rtype: dict[str, Any] @@ -521,19 +520,19 @@ def delete_item( **kwargs # type: Any ): # type: (...) -> None - """ - Delete the specified item from the container. + """Delete the specified item from the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param item: The ID (name) or dict representing item to be deleted. :param partition_key: Specifies the partition key value for the item. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The item wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The item does not exist in the container. :rtype: None @@ -557,10 +556,9 @@ def delete_item( @distributed_trace def read_offer(self, **kwargs): # type: (Any) -> Offer - """ - Read the Offer object for this container. + """Read the Offer object for this container. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: Offer for the container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: No offer exists for the container or the offer could not be retrieved. @@ -587,11 +585,10 @@ def read_offer(self, **kwargs): @distributed_trace def replace_throughput(self, throughput, **kwargs): # type: (int, Any) -> Offer - """ - Replace the container's throughput + """Replace the container's throughput. :param throughput: The throughput to be set (an integer). - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: Offer for the container, updated with new throughput. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: No offer exists for the container or the offer could not be updated. @@ -621,12 +618,12 @@ def replace_throughput(self, throughput, **kwargs): @distributed_trace def list_conflicts(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - List all conflicts in the container. + """List all conflicts in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of conflicts (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -653,18 +650,18 @@ def query_conflicts( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - Return all conflicts matching the given `query`. + """Return all conflicts matching the given `query`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. - :param partition_key: Specifies the partition key value for the item. :param enable_cross_partition_query: Allows sending of more than one request to execute the query in the Azure Cosmos DB service. More than one request is necessary if the query is not scoped to single partition key value. + :param partition_key: Specifies the partition key value for the item. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of conflicts (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -690,13 +687,13 @@ def query_conflicts( @distributed_trace def get_conflict(self, conflict, partition_key, **kwargs): # type: (Union[str, Dict[str, Any]], Any, Any) -> Dict[str, str] - """ - Get the conflict identified by `conflict`. + """Get the conflict identified by `conflict`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param conflict: The ID (name) or dict representing the conflict to retrieve. :param partition_key: Partition key for the conflict to retrieve. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the retrieved conflict. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given conflict couldn't be retrieved. :rtype: dict[str, Any] @@ -716,13 +713,13 @@ def get_conflict(self, conflict, partition_key, **kwargs): @distributed_trace def delete_conflict(self, conflict, partition_key, **kwargs): # type: (Union[str, Dict[str, Any]], Any, Any) -> None - """ - Delete the specified conflict from the container. + """Delete the specified conflict from the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param conflict: The ID (name) or dict representing the conflict to be deleted. :param partition_key: Partition key for the conflict to delete. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The conflict wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The conflict does not exist in the container. :rtype: None diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py index cde949569bc9..53f6f6520311 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py @@ -114,16 +114,14 @@ def _get_properties(self): @distributed_trace def read(self, populate_query_metrics=None, **kwargs): # type: (Optional[bool], Any) -> Dict[str, Any] - """ - Read the database properties. + """Read the database properties. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param database: The ID (name), dict representing the properties or :class:`DatabaseProxy` - instance of the database to read. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param bool populate_query_metrics: Enable returning query metrics in response headers. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :rtype: Dict[Str, Any] :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given database couldn't be retrieved. """ @@ -159,24 +157,23 @@ def create_container( **kwargs # type: Any ): # type: (...) -> ContainerProxy - """ - Create a new container with the given ID (name). + """Create a new container with the given ID (name). If a container with the given ID already exists, a CosmosResourceExistsError is raised. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of container to create. :param partition_key: The partition key to use for the container. :param indexing_policy: The indexing policy to apply to the container. :param default_ttl: Default time to live (TTL) for items in the container. If unspecified, items do not expire. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param offer_throughput: The provisioned throughput for this offer. :param unique_key_policy: The unique key policy to apply to the container. :param conflict_resolution_policy: The conflict resolution policy to apply to the container. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `ContainerProxy` instance representing the new container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container creation failed. :rtype: ~azure.cosmos.ContainerProxy @@ -241,26 +238,25 @@ def create_container_if_not_exists( **kwargs # type: Any ): # type: (...) -> ContainerProxy - """ - Create the container if it does not exist already. + """Create the container if it does not exist already. If the container already exists, the existing settings are returned. Note: it does not check or update the existing container settings or offer throughput if they differ from what was passed into the method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of container to read or create. :param partition_key: The partition key to use for the container. :param indexing_policy: The indexing policy to apply to the container. :param default_ttl: Default time to live (TTL) for items in the container. If unspecified, items do not expire. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. :param offer_throughput: The provisioned throughput for this offer. :param unique_key_policy: The unique key policy to apply to the container. :param conflict_resolution_policy: The conflict resolution policy to apply to the container. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `ContainerProxy` instance representing the container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container read or creation failed. :rtype: ~azure.cosmos.ContainerProxy @@ -293,18 +289,18 @@ def delete_container( **kwargs # type: Any ): # type: (...) -> None - """ - Delete the container + """Delete the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param container: The ID (name) of the container to delete. You can either pass in the ID of the container to delete, a :class:`ContainerProxy` instance or a dict representing the properties of the container. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :param access_condition: Conditions Associated with the request. :param populate_query_metrics: Enable returning query metrics in response headers. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 access_condition: Conditions Associated with the request. + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the container couldn't be deleted. :rtype: None """ @@ -320,8 +316,7 @@ def delete_container( def get_container_client(self, container): # type: (Union[str, ContainerProxy, Dict[str, Any]]) -> ContainerProxy - """ - Get the specified `ContainerProxy`, or a container with specified ID (name). + """Get the specified `ContainerProxy`, or a container with specified ID (name). :param container: The ID (name) of the container, a :class:`ContainerProxy` instance, or a dict representing the properties of the container to be retrieved. @@ -349,15 +344,15 @@ def get_container_client(self, container): @distributed_trace def list_containers(self, max_item_count=None, populate_query_metrics=None, **kwargs): # type: (Optional[int], Optional[bool], Any) -> Iterable[Dict[str, Any]] - """ - List the containers in the database. + """List the containers in the database. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param populate_query_metrics: Enable returning query metrics in response headers. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of container properties (dicts). :rtype: Iterable[dict[str, Any]] @@ -395,17 +390,17 @@ def query_containers( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - List properties for containers in the current database. + """List properties for containers in the current database. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. :param populate_query_metrics: Enable returning query metrics in response headers. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword 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 Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of container properties (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -438,9 +433,11 @@ def replace_container( **kwargs # type: Any ): # type: (...) -> ContainerProxy - """ - Reset the properties of the container. Property changes are persisted immediately. - Any properties not specified will be reset to their default values. + """Reset the properties of the container. + + Property changes are persisted immediately. Any properties not specified will be reset to + their default values. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param container: The ID (name), dict representing the properties or :class:`ContainerProxy` instance of the container to be replaced. @@ -449,12 +446,11 @@ def replace_container( :param default_ttl: Default time to live (TTL) for items in the container. If unspecified, items do not expire. :param conflict_resolution_policy: The conflict resolution policy to apply to the container. - :param session_token: Token for use with Session consistency. - :param access_condition: Conditions Associated with the request. - :param initial_headers: Initial headers to be sent as part of the request. :param populate_query_metrics: Enable returning query metrics in response headers. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword session_token: Token for use with Session consistency. + :keyword access_condition: Conditions Associated with the request. + :keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request. + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Raised if the container couldn't be replaced. This includes if the container with given id does not exist. :returns: A `ContainerProxy` instance representing the container after replace completed. @@ -503,12 +499,12 @@ def replace_container( @distributed_trace def list_users(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - List all users in the container. + """List all users in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of users to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of user properties (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -527,14 +523,14 @@ def list_users(self, max_item_count=None, **kwargs): @distributed_trace def query_users(self, query, parameters=None, max_item_count=None, **kwargs): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - Return all users matching the given `query`. + """Return all users matching the given `query`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of users to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of user properties (dicts). :rtype: Iterable[str, Any] """ @@ -555,8 +551,7 @@ def query_users(self, query, parameters=None, max_item_count=None, **kwargs): def get_user_client(self, user): # type: (Union[str, UserProxy, Dict[str, Any]]) -> UserProxy - """ - Get the user identified by `user`. + """Get the user identified by `user`. :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be retrieved. @@ -576,14 +571,14 @@ def get_user_client(self, user): @distributed_trace def create_user(self, body, **kwargs): # type: (Dict[str, Any], Any) -> UserProxy - """ - Create a user in the container. + """Create a user in the container. + To update or replace an existing user, use the :func:`ContainerProxy.upsert_user` method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object with an `id` key and value representing the user to be created. The user ID must be unique within the database, and consist of no more than 255 characters. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `UserProxy` instance representing the new user. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user couldn't be created. :rtype: ~azure.cosmos.UserProxy @@ -614,13 +609,13 @@ def create_user(self, body, **kwargs): @distributed_trace def upsert_user(self, body, **kwargs): # type: (Dict[str, Any], Any) -> UserProxy - """ - Insert or update the specified user. + """Insert or update the specified user. + If the user already exists in the container, it is replaced. If it does not, it is inserted. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the user to update or insert. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `UserProxy` instance representing the upserted user. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user could not be upserted. :rtype: ~azure.cosmos.UserProxy @@ -647,14 +642,14 @@ def replace_user( **kwargs # type: Any ): # type: (...) -> UserProxy - """ - Replaces the specified user if it exists in the container. + """Replaces the specified user if it exists in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be replaced. :param body: A dict-like object representing the user to replace. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `UserProxy` instance representing the user after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the user with given id does not exist. @@ -680,13 +675,13 @@ def replace_user( @distributed_trace def delete_user(self, user, **kwargs): # type: (Union[str, UserProxy, Dict[str, Any]], Any) -> None - """ - Delete the specified user from the container. + """Delete the specified user from the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be deleted. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The user wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The user does not exist in the container. :rtype: None @@ -703,10 +698,9 @@ def delete_user(self, user, **kwargs): @distributed_trace def read_offer(self, **kwargs): # type: (Any) -> Offer - """ - Read the Offer object for this database. + """Read the Offer object for this database. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: Offer for the database. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If no offer exists for the database or if the offer could not be retrieved. @@ -733,11 +727,10 @@ def read_offer(self, **kwargs): @distributed_trace def replace_throughput(self, throughput, **kwargs): # type: (Optional[int], Any) -> Offer - """ - Replace the database level throughput. + """Replace the database level throughput. :param throughput: The throughput to be set (an integer). - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: Offer for the database, updated with new throughput. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If no offer exists for the database or if the offer could not be updated. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py b/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py index 2cc4cb4efcef..f00faba78e0c 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py @@ -60,11 +60,11 @@ def _get_resource_link(self, script_or_id, typ): def list_stored_procedures(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - List all stored procedures in the container. + """List all stored procedures in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param int max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. :returns: An Iterable of stored procedures (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -78,13 +78,13 @@ def list_stored_procedures(self, max_item_count=None, **kwargs): def query_stored_procedures(self, query, parameters=None, max_item_count=None, **kwargs): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - Return all stored procedures matching the given `query`. + """Return all stored procedures matching the given `query`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. :returns: An Iterable of stored procedures (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -101,11 +101,11 @@ def query_stored_procedures(self, query, parameters=None, max_item_count=None, * def get_stored_procedure(self, sproc, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> Dict[str, Any] - """ - Get the stored procedure identified by `id`. + """Get the stored procedure identified by `id`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param sproc: The ID (name) or dict representing stored procedure to retrieve. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the retrieved stored procedure. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given stored procedure couldn't be retrieved. :rtype: dict[str, Any] @@ -118,12 +118,12 @@ def get_stored_procedure(self, sproc, **kwargs): def create_stored_procedure(self, body, **kwargs): # type: (Dict[str, Any], Any) -> Dict[str, Any] - """ - Create a stored procedure in the container. + """Create a stored procedure in the container. + To replace an existing sproc, use the :func:`Container.scripts.replace_stored_procedure` method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the sproc to create. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the new stored procedure. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given stored procedure couldn't be created. :rtype: dict[str, Any] @@ -136,12 +136,12 @@ def create_stored_procedure(self, body, **kwargs): def replace_stored_procedure(self, sproc, body, **kwargs): # type: (Union[str, Dict[str, Any]], Dict[str, Any], Any) -> Dict[str, Any] - """ - Replaces the specified stored procedure if it exists in the container. + """Replaces the specified stored procedure if it exists in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param sproc: The ID (name) or dict representing stored procedure to be replaced. :param body: A dict-like object representing the sproc to replace. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the stored procedure after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the stored procedure with given id does not exist. @@ -158,11 +158,11 @@ def replace_stored_procedure(self, sproc, body, **kwargs): def delete_stored_procedure(self, sproc, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> None - """ - Delete the specified stored procedure from the container. + """Delete the specified stored procedure from the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param sproc: The ID (name) or dict representing stored procedure to be deleted. - :param request_options: Dictionary of additional properties to be used for the request. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The sproc wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The sproc does not exist in the container. :rtype: None @@ -182,14 +182,14 @@ def execute_stored_procedure( **kwargs # type: Any ): # type: (...) -> Any - """ - Execute the specified stored procedure. + """Execute the specified stored procedure. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param sproc: The ID (name) or dict representing stored procedure to be executed. + :param partition_key: Specifies the partition key to indicate which partition the sproc should execute on. :param params: List of parameters to be passed to the stored procedure to be executed. :param bool enable_script_logging: Enables or disables script logging for the current request. - :param partition_key: Specifies the partition key to indicate which partition the sproc should execute on. - :param request_options: Dictionary of additional properties to be used for the request. :returns: Result of the executed stored procedure for the given parameters. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the stored procedure execution failed or if the stored procedure with given id does not exists in the container. @@ -215,11 +215,11 @@ def execute_stored_procedure( def list_triggers(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - List all triggers in the container. + """List all triggers in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. :returns: An Iterable of triggers (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -233,13 +233,13 @@ def list_triggers(self, max_item_count=None, **kwargs): def query_triggers(self, query, parameters=None, max_item_count=None, **kwargs): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - Return all triggers matching the given `query`. + """Return all triggers matching the given `query`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. :returns: An Iterable of triggers (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -256,11 +256,11 @@ def query_triggers(self, query, parameters=None, max_item_count=None, **kwargs): def get_trigger(self, trigger, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> Dict[str, Any] - """ - Get the trigger identified by `id`. + """Get the trigger identified by `id`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param trigger: The ID (name) or dict representing trigger to retrieve. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the retrieved trigger. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given trigger couldn't be retrieved. :rtype: dict[str, Any] @@ -273,12 +273,12 @@ def get_trigger(self, trigger, **kwargs): def create_trigger(self, body, **kwargs): # type: (Dict[str, Any], Any) -> Dict[str, Any] - """ - Create a trigger in the container. + """Create a trigger in the container. + To replace an existing trigger, use the :func:`ContainerProxy.scripts.replace_trigger` method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the trigger to create. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the new trigger. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given trigger couldn't be created. :rtype: dict[str, Any] @@ -291,12 +291,12 @@ def create_trigger(self, body, **kwargs): def replace_trigger(self, trigger, body, **kwargs): # type: (Union[str, Dict[str, Any]], Dict[str, Any], Any) -> Dict[str, Any] - """ - Replaces the specified tigger if it exists in the container. + """Replaces the specified tigger if it exists in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param trigger: The ID (name) or dict representing trigger to be replaced. :param body: A dict-like object representing the trigger to replace. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the trigger after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the trigger with given id does not exist. @@ -313,11 +313,11 @@ def replace_trigger(self, trigger, body, **kwargs): def delete_trigger(self, trigger, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> None - """ - Delete the specified trigger from the container. + """Delete the specified trigger from the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param trigger: The ID (name) or dict representing trigger to be deleted. - :param request_options: Dictionary of additional properties to be used for the request. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The trigger wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The trigger does not exist in the container. :rtype: None @@ -330,11 +330,11 @@ def delete_trigger(self, trigger, **kwargs): def list_user_defined_functions(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - List all user defined functions in the container. + """List all user defined functions in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. :returns: An Iterable of user defined functions (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -351,10 +351,11 @@ def query_user_defined_functions(self, query, parameters=None, max_item_count=No """ Return all user defined functions matching the given `query`. + See aka.ms/{} for a full list of optional request and feed keyword arguments. + :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. :returns: An Iterable of user defined functions (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -371,11 +372,11 @@ def query_user_defined_functions(self, query, parameters=None, max_item_count=No def get_user_defined_function(self, udf, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> Dict[str, Any] - """ - Get the stored procedure identified by `id`. + """Get the stored procedure identified by `id`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param udf: The ID (name) or dict representing udf to retrieve. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the retrieved user defined function. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the user defined function couldn't be retrieved. :rtype: Iterable[dict[str, Any]] @@ -388,12 +389,12 @@ def get_user_defined_function(self, udf, **kwargs): def create_user_defined_function(self, body, **kwargs): # type: (Dict[str, Any], Any) -> Dict[str, Any] - """ - Create a user defined function in the container. + """Create a user defined function in the container. + To replace an existing udf, use the :func:`ContainerProxy.scripts.replace_user_defined_function` method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the udf to create. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the new user defined function. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the user defined function couldn't be created. :rtype: dict[str, Any] @@ -406,12 +407,12 @@ def create_user_defined_function(self, body, **kwargs): def replace_user_defined_function(self, udf, body, **kwargs): # type: (Union[str, Dict[str, Any]], Dict[str, Any], Any) -> Dict[str, Any] - """ - Replaces the specified user defined function if it exists in the container. + """Replaces the specified user defined function if it exists in the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param udf: The ID (name) or dict representing udf to be replaced. :param body: A dict-like object representing the udf to replace. - :param request_options: Dictionary of additional properties to be used for the request. :returns: A dict representing the user defined function after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the user defined function with the given id does not exist. @@ -428,11 +429,11 @@ def replace_user_defined_function(self, udf, body, **kwargs): def delete_user_defined_function(self, udf, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> None - """ - Delete the specified user defined function from the container. + """Delete the specified user defined function from the container. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param udf: The ID (name) or dict representing udf to be deleted. - :param request_options: Dictionary of additional properties to be used for the request. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The udf wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The UDF does not exist in the container. :rtype: None diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/user.py b/sdk/cosmos/azure-cosmos/azure/cosmos/user.py index 03d6690d7d47..4fc405aebf09 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/user.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/user.py @@ -70,12 +70,12 @@ def _get_properties(self): @distributed_trace def read(self, **kwargs): # type: (Any) -> Dict[str, Any] - """ - Read user propertes. + """Read user propertes. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata - :returns: A :class:`UserProxy` instance representing the retrieved user. + :keyword Callable response_hook: a callable invoked with the response metadata + :returns: A dictionary of the retrieved user properties. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user couldn't be retrieved. :rtype: dict[str, Any] """ @@ -92,12 +92,12 @@ def read(self, **kwargs): @distributed_trace def list_permissions(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - List all permission for the user. + """List all permission for the user. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of permissions to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of permissions (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -122,14 +122,14 @@ def query_permissions( **kwargs ): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - Return all permissions matching the given `query`. + """Return all permissions matching the given `query`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of permissions to be returned in the enumeration operation. - :param feed_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of permissions (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -153,13 +153,13 @@ def query_permissions( @distributed_trace def get_permission(self, permission, **kwargs): # type: (str, Any) -> Permission - """ - Get the permission identified by `id`. + """Get the permission identified by `id`. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be retrieved. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the retrieved permission. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission couldn't be retrieved. :rtype: dict[str, Any] @@ -185,13 +185,13 @@ def get_permission(self, permission, **kwargs): @distributed_trace def create_permission(self, body, **kwargs): # type: (Dict[str, Any], Any) -> Permission - """ - Create a permission for the user. + """Create a permission for the user. + To update or replace an existing permision, use the :func:`UserProxy.upsert_permission` method. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the permission to create. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the new permission. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission couldn't be created. :rtype: dict[str, Any] @@ -217,13 +217,13 @@ def create_permission(self, body, **kwargs): @distributed_trace def upsert_permission(self, body, **kwargs): # type: (Dict[str, Any], Any) -> Permission - """ - Insert or update the specified permission. + """Insert or update the specified permission. + If the permission already exists in the container, it is replaced. If it does not, it is inserted. + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the permission to update or insert. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :param Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the upserted permission. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission could not be upserted. :rtype: dict[str, Any] @@ -249,14 +249,14 @@ def upsert_permission(self, body, **kwargs): @distributed_trace def replace_permission(self, permission, body, **kwargs): # type: (str, Dict[str, Any], Any) -> Permission - """ - Replaces the specified permission if it exists for the user. + """Replaces the specified permission if it exists for the user. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be replaced. :param body: A dict-like object representing the permission to replace. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the permission after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the permission with given id does not exist. @@ -283,13 +283,13 @@ def replace_permission(self, permission, body, **kwargs): @distributed_trace def delete_permission(self, permission, **kwargs): # type: (str, Any) -> None - """ - Delete the specified permission from the user. + """Delete the specified permission from the user. + + See aka.ms/{} for a full list of optional request and feed keyword arguments. :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be replaced. - :param request_options: Dictionary of additional properties to be used for the request. - :param response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The permission wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The permission does not exist for the user. :rtype: None From 082926a2073794b9665b634e852d82fbf6249118 Mon Sep 17 00:00:00 2001 From: antisch Date: Tue, 29 Oct 2019 15:34:18 -0700 Subject: [PATCH 04/12] Updated access condition kwargs --- sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | 35 ++++++++++++++++--- .../azure-cosmos/azure/cosmos/container.py | 16 ++++++--- .../azure/cosmos/cosmos_client.py | 31 ++++++++-------- .../azure-cosmos/azure/cosmos/database.py | 16 ++++++--- sdk/cosmos/azure-cosmos/test/crud_tests.py | 4 ++- 5 files changed, 74 insertions(+), 28 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py index f67497cf6f6a..3a2eb1ba63d3 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py @@ -32,6 +32,8 @@ import six from six.moves.urllib.parse import quote as urllib_quote +from azure.core import MatchConditions + from . import auth from . import documents from . import partition_key @@ -70,6 +72,30 @@ 'query_version': 'queryVersion' } +def _get_match_headers(kwargs, match_param, etag_param): + # type: (str) -> Tuple(Dict[str, Any], Optional[str], Optional[str]) + if_match = kwargs.pop('if_match', None) + if_none_match = kwargs.pop('if_none_match', None) + match_condition = kwargs.pop(match_param, None) + if match_condition == MatchConditions.IfNotModified: + if_match = kwargs.pop(etag_param, None) + if not if_match: + raise ValueError("'{}' specified without '{}'.".format(match_param, etag_param)) + elif match_condition == MatchConditions.IfPresent: + if_match = '*' + elif match_condition == MatchConditions.IfModified: + if_none_match = kwargs.pop(etag_param, None) + if not if_none_match: + raise ValueError("'{}' specified without '{}'.".format(match_param, etag_param)) + elif match_condition == MatchConditions.IfMissing: + if_none_match = '*' + elif match_condition is None: + if etag_param in kwargs: + raise ValueError("'{}' specified without '{}'.".format(etag_param, match_param)) + else: + raise TypeError("Invalid match condition: {}".format(match_condition)) + return if_match, if_none_match + def build_options(kwargs): # type: (Dict[str, Any]) -> Dict[str, Any] options = kwargs.pop('request_options', kwargs.pop('feed_options', {})) @@ -77,10 +103,11 @@ def build_options(kwargs): if key in kwargs: options[value] = kwargs.pop(key) - if 'if_match' in kwargs: - options['accessCondition'] = {'type': 'IfMatch', 'condition': kwargs.pop('if_match')} - if 'if_none_match' in kwargs: - options['accessCondition'] = {'type': 'IfNoneMatch', 'condition': kwargs.pop('if_none_match')} + if_match, if_none_match = _get_match_headers(kwargs, 'match_condition', 'etag') + if if_match: + options['accessCondition'] = {'type': 'IfMatch', 'condition': if_match} + if if_none_match: + options['accessCondition'] = {'type': 'IfNoneMatch', 'condition': if_none_match} return options diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py index 8986db05266f..1592ea2d4fee 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py @@ -392,7 +392,9 @@ def replace_item( :param post_trigger_include: trigger id to be used as post operation trigger. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the item after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The replace failed or the item with @@ -438,7 +440,9 @@ def upsert_item( :param post_trigger_include: trigger id to be used as post operation trigger. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the upserted item. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item could not be upserted. @@ -483,7 +487,9 @@ def create_item( :param indexing_directive: Indicate whether the document should be omitted from indexing. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A dict representing the new item. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Item with the given ID already exists. @@ -531,7 +537,9 @@ def delete_item( :param post_trigger_include: trigger id to be used as post operation trigger. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The item wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The item does not exist in the container. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py index ca69226fd0a7..b17473be99eb 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py @@ -233,13 +233,13 @@ def create_database( # pylint: disable=redefined-builtin See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of the database to create. - :param str session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :type initial_headers: dict[str, str] - :param access_condition: Conditions Associated with the request. - :type access_condition: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. :param int offer_throughput: The provisioned throughput for this offer. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A DatabaseProxy instance representing the new database. :rtype: ~azure.cosmos.DatabaseProxy @@ -285,14 +285,14 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin if they differ from what was passed into the method. See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param id: ID (name) of the database to read or create. - :param str session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :type initial_headers: dict[str, str] - :param access_condition: Conditions Associated with the request. - :type access_condition: dict[str, str] + :param id: ID (name) of the database to read or create. :param bool populate_query_metrics: Enable returning query metrics in response headers. :param int offer_throughput: The provisioned throughput for this offer. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A DatabaseProxy instance representing the database. :rtype: ~azure.cosmos.DatabaseProxy @@ -345,10 +345,9 @@ def list_databases( See aka.ms/{} for a full list of optional request and feed keyword arguments. :param int max_item_count: Max number of items to be returned in the enumeration operation. - :param str session_token: Token for use with Session consistency. - :param initial_headers: Initial headers to be sent as part of the request. - :type initial_headers: dict[str, str] :param bool populate_query_metrics: Enable returning query metrics in response headers. + :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 Callable response_hook: a callable invoked with the response metadata :returns: An Iterable of database properties (dicts). :rtype: Iterable[dict[str, str]] @@ -435,7 +434,9 @@ def delete_database( :param bool populate_query_metrics: Enable returning query metrics in response headers. :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 dict[str,str] access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the database couldn't be deleted. :rtype: None diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py index 53f6f6520311..de5d5b864b5c 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py @@ -172,7 +172,9 @@ def create_container( :param conflict_resolution_policy: The conflict resolution policy to apply to the container. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `ContainerProxy` instance representing the new container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container creation failed. @@ -255,7 +257,9 @@ def create_container_if_not_exists( :param conflict_resolution_policy: The conflict resolution policy to apply to the container. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :returns: A `ContainerProxy` instance representing the container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container read or creation failed. @@ -299,7 +303,9 @@ def delete_container( :param populate_query_metrics: Enable returning query metrics in response headers. :keyword 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 access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the container couldn't be deleted. :rtype: None @@ -448,7 +454,9 @@ def replace_container( :param conflict_resolution_policy: The conflict resolution policy to apply to the container. :param populate_query_metrics: Enable returning query metrics in response headers. :keyword session_token: Token for use with Session consistency. - :keyword access_condition: Conditions Associated with the request. + :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource + has changed, and act according to the condition specified by the `match_condition` parameter. + :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request. :keyword Callable response_hook: a callable invoked with the response metadata :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Raised if the container couldn't be replaced. diff --git a/sdk/cosmos/azure-cosmos/test/crud_tests.py b/sdk/cosmos/azure-cosmos/test/crud_tests.py index dd751cf223d2..d62b52560920 100644 --- a/sdk/cosmos/azure-cosmos/test/crud_tests.py +++ b/sdk/cosmos/azure-cosmos/test/crud_tests.py @@ -41,6 +41,7 @@ import urllib.parse as urllib import uuid import pytest +from azure.core import MatchConditions from azure.core.exceptions import AzureError, ServiceResponseError from azure.core.pipeline.transport import RequestsTransport, RequestsTransportResponse from azure.cosmos import _consistent_hash_ring @@ -859,7 +860,8 @@ def test_document_crud(self): # should pass for most recent etag replaced_document_conditional = created_collection.replace_item( - access_condition={'type': 'IfMatch', 'condition': replaced_document['_etag']}, + match_condition=MatchConditions.IfNotModified, + etag=replaced_document['_etag'], item=replaced_document['id'], body=replaced_document ) From 0a1e622fcbc640b3aa591ac3abbbbac6b9a49d44 Mon Sep 17 00:00:00 2001 From: antisch Date: Tue, 29 Oct 2019 15:37:26 -0700 Subject: [PATCH 05/12] More docs cleanup --- sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | 1 + .../azure-cosmos/azure/cosmos/container.py | 46 +++++++++---------- .../azure/cosmos/cosmos_client.py | 12 ++--- .../azure-cosmos/azure/cosmos/database.py | 44 +++++++++--------- sdk/cosmos/azure-cosmos/azure/cosmos/user.py | 16 +++---- 5 files changed, 60 insertions(+), 59 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py index 3a2eb1ba63d3..355cd1a1ae11 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py @@ -96,6 +96,7 @@ def _get_match_headers(kwargs, match_param, etag_param): raise TypeError("Invalid match condition: {}".format(match_condition)) return if_match, if_none_match + def build_options(kwargs): # type: (Dict[str, Any]) -> Dict[str, Any] options = kwargs.pop('request_options', kwargs.pop('feed_options', {})) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py index 1592ea2d4fee..7c4e268c62fa 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py @@ -128,9 +128,9 @@ def read( :param populate_partition_key_range_statistics: Enable returning partition key range statistics in response headers. :param populate_quota_info: Enable returning collection storage quota information in response headers. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Raised if the container couldn't be retrieved. This includes if the container does not exist. :returns: Dict representing the retrieved container. @@ -173,9 +173,9 @@ def read_item( :param partition_key: Partition key for the item to retrieve. :param populate_query_metrics: Enable returning query metrics in response headers. :param post_trigger_include: trigger id to be used as post operation trigger. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: Dict representing the item to be retrieved. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item couldn't be retrieved. :rtype: dict[str, Any] @@ -220,9 +220,9 @@ def read_all_items( :param max_item_count: Max number of items to be returned in the enumeration operation. :param populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of items (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -263,7 +263,7 @@ def query_items_change_feed( beginning (true) or from current (false). By default it's start from current (false). :param continuation: e_tag value to be used as continuation for reading change feed. :param max_item_count: Max number of items to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of items (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -318,9 +318,9 @@ def query_items( :param enable_scan_in_query: Allow scan on the queries which couldn't be served as indexing was opted out on the requested paths. :param populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of items (dicts). :rtype: Iterable[dict[str, Any]] @@ -390,12 +390,12 @@ def replace_item( :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the item after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The replace failed or the item with given id does not exist. @@ -438,12 +438,12 @@ def upsert_item( :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the upserted item. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item could not be upserted. :rtype: dict[str, Any] @@ -485,12 +485,12 @@ def create_item( :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. :param indexing_directive: Indicate whether the document should be omitted from indexing. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the new item. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Item with the given ID already exists. :rtype: dict[str, Any] @@ -535,12 +535,12 @@ def delete_item( :param populate_query_metrics: Enable returning query metrics in response headers. :param pre_trigger_include: trigger id to be used as pre operation trigger. :param post_trigger_include: trigger id to be used as post operation trigger. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The item wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The item does not exist in the container. :rtype: None @@ -566,7 +566,7 @@ def read_offer(self, **kwargs): # type: (Any) -> Offer """Read the Offer object for this container. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: Offer for the container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: No offer exists for the container or the offer could not be retrieved. @@ -596,7 +596,7 @@ def replace_throughput(self, throughput, **kwargs): """Replace the container's throughput. :param throughput: The throughput to be set (an integer). - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: Offer for the container, updated with new throughput. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: No offer exists for the container or the offer could not be updated. @@ -631,7 +631,7 @@ def list_conflicts(self, max_item_count=None, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of items to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of conflicts (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -669,7 +669,7 @@ def query_conflicts( More than one request is necessary if the query is not scoped to single partition key value. :param partition_key: Specifies the partition key value for the item. :param max_item_count: Max number of items to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of conflicts (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -701,7 +701,7 @@ def get_conflict(self, conflict, partition_key, **kwargs): :param conflict: The ID (name) or dict representing the conflict to retrieve. :param partition_key: Partition key for the conflict to retrieve. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the retrieved conflict. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given conflict couldn't be retrieved. :rtype: dict[str, Any] @@ -727,7 +727,7 @@ def delete_conflict(self, conflict, partition_key, **kwargs): :param conflict: The ID (name) or dict representing the conflict to be deleted. :param partition_key: Partition key for the conflict to delete. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The conflict wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The conflict does not exist in the container. :rtype: None diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py index b17473be99eb..f1958dbccd78 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py @@ -240,7 +240,7 @@ def create_database( # pylint: disable=redefined-builtin :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A DatabaseProxy instance representing the new database. :rtype: ~azure.cosmos.DatabaseProxy :raises ~azure.cosmos.exceptions.CosmosResourceExistsError: Database with the given ID already exists. @@ -293,7 +293,7 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A DatabaseProxy instance representing the database. :rtype: ~azure.cosmos.DatabaseProxy :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The database read or creation failed. @@ -348,7 +348,7 @@ def list_databases( :param bool populate_query_metrics: Enable returning query metrics in response headers. :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of database properties (dicts). :rtype: Iterable[dict[str, str]] """ @@ -388,7 +388,7 @@ def query_databases( :param bool populate_query_metrics: Enable returning query metrics in response headers. :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of database properties (dicts). :rtype: Iterable[dict[str, str]] """ @@ -437,7 +437,7 @@ def delete_database( :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the database couldn't be deleted. :rtype: None """ @@ -457,7 +457,7 @@ def get_database_account(self, **kwargs): """ Retrieve the database account information. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A `DatabaseAccount` instance representing the Cosmos DB Database Account. :rtype: ~azure.cosmos.DatabaseAccount """ diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py index de5d5b864b5c..7e53c52a213b 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py @@ -119,9 +119,9 @@ def read(self, populate_query_metrics=None, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param bool populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :rtype: Dict[Str, Any] :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given database couldn't be retrieved. """ @@ -170,12 +170,12 @@ def create_container( :param offer_throughput: The provisioned throughput for this offer. :param unique_key_policy: The unique key policy to apply to the container. :param conflict_resolution_policy: The conflict resolution policy to apply to the container. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A `ContainerProxy` instance representing the new container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container creation failed. :rtype: ~azure.cosmos.ContainerProxy @@ -255,12 +255,12 @@ def create_container_if_not_exists( :param offer_throughput: The provisioned throughput for this offer. :param unique_key_policy: The unique key policy to apply to the container. :param conflict_resolution_policy: The conflict resolution policy to apply to the container. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A `ContainerProxy` instance representing the container. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container read or creation failed. :rtype: ~azure.cosmos.ContainerProxy @@ -301,12 +301,12 @@ def delete_container( pass in the ID of the container to delete, a :class:`ContainerProxy` instance or a dict representing the properties of the container. :param populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the container couldn't be deleted. :rtype: None """ @@ -356,9 +356,9 @@ def list_containers(self, max_item_count=None, populate_query_metrics=None, **kw :param max_item_count: Max number of items to be returned in the enumeration operation. :param populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of container properties (dicts). :rtype: Iterable[dict[str, Any]] @@ -404,9 +404,9 @@ def query_containers( :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. :param populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :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 Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of container properties (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -453,12 +453,12 @@ def replace_container( If unspecified, items do not expire. :param conflict_resolution_policy: The conflict resolution policy to apply to the container. :param populate_query_metrics: Enable returning query metrics in response headers. - :keyword session_token: Token for use with Session consistency. + :keyword str session_token: Token for use with Session consistency. :keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the `match_condition` parameter. :keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag. :keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Raised if the container couldn't be replaced. This includes if the container with given id does not exist. :returns: A `ContainerProxy` instance representing the container after replace completed. @@ -512,7 +512,7 @@ def list_users(self, max_item_count=None, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of users to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of user properties (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -538,7 +538,7 @@ def query_users(self, query, parameters=None, max_item_count=None, **kwargs): :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of users to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of user properties (dicts). :rtype: Iterable[str, Any] """ @@ -586,7 +586,7 @@ def create_user(self, body, **kwargs): :param body: A dict-like object with an `id` key and value representing the user to be created. The user ID must be unique within the database, and consist of no more than 255 characters. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A `UserProxy` instance representing the new user. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user couldn't be created. :rtype: ~azure.cosmos.UserProxy @@ -623,7 +623,7 @@ def upsert_user(self, body, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the user to update or insert. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A `UserProxy` instance representing the upserted user. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user could not be upserted. :rtype: ~azure.cosmos.UserProxy @@ -657,7 +657,7 @@ def replace_user( :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be replaced. :param body: A dict-like object representing the user to replace. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A `UserProxy` instance representing the user after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the user with given id does not exist. @@ -689,7 +689,7 @@ def delete_user(self, user, **kwargs): :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be deleted. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The user wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The user does not exist in the container. :rtype: None @@ -708,7 +708,7 @@ def read_offer(self, **kwargs): # type: (Any) -> Offer """Read the Offer object for this database. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: Offer for the database. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If no offer exists for the database or if the offer could not be retrieved. @@ -738,7 +738,7 @@ def replace_throughput(self, throughput, **kwargs): """Replace the database level throughput. :param throughput: The throughput to be set (an integer). - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: Offer for the database, updated with new throughput. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If no offer exists for the database or if the offer could not be updated. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/user.py b/sdk/cosmos/azure-cosmos/azure/cosmos/user.py index 4fc405aebf09..a92c08397151 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/user.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/user.py @@ -74,7 +74,7 @@ def read(self, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dictionary of the retrieved user properties. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user couldn't be retrieved. :rtype: dict[str, Any] @@ -97,7 +97,7 @@ def list_permissions(self, max_item_count=None, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param max_item_count: Max number of permissions to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of permissions (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -129,7 +129,7 @@ def query_permissions( :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of permissions to be returned in the enumeration operation. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of permissions (dicts). :rtype: Iterable[dict[str, Any]] """ @@ -159,7 +159,7 @@ def get_permission(self, permission, **kwargs): :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be retrieved. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the retrieved permission. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission couldn't be retrieved. :rtype: dict[str, Any] @@ -191,7 +191,7 @@ def create_permission(self, body, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the permission to create. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the new permission. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission couldn't be created. :rtype: dict[str, Any] @@ -223,7 +223,7 @@ def upsert_permission(self, body, **kwargs): See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the permission to update or insert. - :param Callable response_hook: a callable invoked with the response metadata + :param Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the upserted permission. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission could not be upserted. :rtype: dict[str, Any] @@ -256,7 +256,7 @@ def replace_permission(self, permission, body, **kwargs): :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be replaced. :param body: A dict-like object representing the permission to replace. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dict representing the permission after replace went through. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the permission with given id does not exist. @@ -289,7 +289,7 @@ def delete_permission(self, permission, **kwargs): :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be replaced. - :keyword Callable response_hook: a callable invoked with the response metadata + :keyword Callable response_hook: A callable invoked with the response metadata. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The permission wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The permission does not exist for the user. :rtype: None From e57840309ef73b15148650afd8fa218814b67528 Mon Sep 17 00:00:00 2001 From: antisch Date: Tue, 29 Oct 2019 16:00:10 -0700 Subject: [PATCH 06/12] Whitespace --- sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py | 2 +- sdk/cosmos/azure-cosmos/azure/cosmos/database.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py index f1958dbccd78..1e2ec93bf08e 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py @@ -285,7 +285,7 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin if they differ from what was passed into the method. See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param id: ID (name) of the database to read or create. + :param id: ID (name) of the database to read or create. :param bool populate_query_metrics: Enable returning query metrics in response headers. :param int offer_throughput: The provisioned throughput for this offer. :keyword str session_token: Token for use with Session consistency. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py index 7e53c52a213b..1f5cc7ace975 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py @@ -440,7 +440,7 @@ def replace_container( ): # type: (...) -> ContainerProxy """Reset the properties of the container. - + Property changes are persisted immediately. Any properties not specified will be reset to their default values. See aka.ms/{} for a full list of optional request and feed keyword arguments. From 34195cafc609c47fafd8245dc309f36e18408580 Mon Sep 17 00:00:00 2001 From: antisch Date: Wed, 30 Oct 2019 07:33:04 -0700 Subject: [PATCH 07/12] Removed URLs for now --- .../azure-cosmos/azure/cosmos/container.py | 23 ----------- .../azure/cosmos/cosmos_client.py | 15 +------- .../azure-cosmos/azure/cosmos/database.py | 21 ---------- .../azure-cosmos/azure/cosmos/scripts.py | 38 +------------------ sdk/cosmos/azure-cosmos/azure/cosmos/user.py | 14 ------- 5 files changed, 3 insertions(+), 108 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py index 7c4e268c62fa..e2853c059272 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/container.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/container.py @@ -122,8 +122,6 @@ def read( # type: (...) -> Dict[str, Any] """Read the container properties. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param populate_query_metrics: Enable returning query metrics in response headers. :param populate_partition_key_range_statistics: Enable returning partition key range statistics in response headers. @@ -167,8 +165,6 @@ def read_item( # type: (...) -> Dict[str, str] """Get the item identified by `item`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param item: The ID (name) or dict representing item to retrieve. :param partition_key: Partition key for the item to retrieve. :param populate_query_metrics: Enable returning query metrics in response headers. @@ -216,8 +212,6 @@ def read_all_items( # type: (...) -> Iterable[Dict[str, Any]] """List all items in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of items to be returned in the enumeration operation. :param populate_query_metrics: Enable returning query metrics in response headers. :keyword str session_token: Token for use with Session consistency. @@ -255,8 +249,6 @@ def query_items_change_feed( # type: (...) -> Iterable[Dict[str, Any]] """Get a sorted list of items that were changed, in the order in which they were modified. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param partition_key_range_id: ChangeFeed requests can be executed against specific partition key ranges. This is used to process the change feed in parallel across multiple consumers. :param is_start_from_beginning: Get whether change feed should start from @@ -306,7 +298,6 @@ def query_items( You can use any value for the container name in the FROM clause, but typically the container name is used. In the examples below, the container name is "products," and is aliased as "p" for easier referencing in the WHERE clause. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. @@ -383,8 +374,6 @@ def replace_item( # type: (...) -> Dict[str, str] """Replaces the specified item if it exists in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param item: The ID (name) or dict representing item to be replaced. :param body: A dict-like object representing the item to replace. :param populate_query_metrics: Enable returning query metrics in response headers. @@ -432,7 +421,6 @@ def upsert_item( """Insert or update the specified item. If the item already exists in the container, it is replaced. If it does not, it is inserted. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the item to update or insert. :param populate_query_metrics: Enable returning query metrics in response headers. @@ -478,7 +466,6 @@ def create_item( """Create an item in the container. To update or replace an existing item, use the :func:`ContainerProxy.upsert_item` method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the item to create. :param populate_query_metrics: Enable returning query metrics in response headers. @@ -528,8 +515,6 @@ def delete_item( # type: (...) -> None """Delete the specified item from the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param item: The ID (name) or dict representing item to be deleted. :param partition_key: Specifies the partition key value for the item. :param populate_query_metrics: Enable returning query metrics in response headers. @@ -628,8 +613,6 @@ def list_conflicts(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] """List all conflicts in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of items to be returned in the enumeration operation. :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of conflicts (dicts). @@ -660,8 +643,6 @@ def query_conflicts( # type: (...) -> Iterable[Dict[str, Any]] """Return all conflicts matching the given `query`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param enable_cross_partition_query: Allows sending of more than one request to execute @@ -697,8 +678,6 @@ def get_conflict(self, conflict, partition_key, **kwargs): # type: (Union[str, Dict[str, Any]], Any, Any) -> Dict[str, str] """Get the conflict identified by `conflict`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param conflict: The ID (name) or dict representing the conflict to retrieve. :param partition_key: Partition key for the conflict to retrieve. :keyword Callable response_hook: A callable invoked with the response metadata. @@ -723,8 +702,6 @@ def delete_conflict(self, conflict, partition_key, **kwargs): # type: (Union[str, Dict[str, Any]], Any, Any) -> None """Delete the specified conflict from the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param conflict: The ID (name) or dict representing the conflict to be deleted. :param partition_key: Partition key for the conflict to delete. :keyword Callable response_hook: A callable invoked with the response metadata. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py index 1e2ec93bf08e..aeca4e68de5f 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py @@ -230,8 +230,6 @@ def create_database( # pylint: disable=redefined-builtin """ Create a new database with the given ID (name). - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param id: ID (name) of the database to create. :param bool populate_query_metrics: Enable returning query metrics in response headers. :param int offer_throughput: The provisioned throughput for this offer. @@ -283,7 +281,6 @@ def create_database_if_not_exists( # pylint: disable=redefined-builtin If the database already exists, the existing settings are returned. Note: it does not check or update the existing database settings or offer throughput if they differ from what was passed into the method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of the database to read or create. :param bool populate_query_metrics: Enable returning query metrics in response headers. @@ -342,8 +339,6 @@ def list_databases( # type: (...) -> Iterable[Dict[str, Any]] """List the databases in a Cosmos DB SQL database account. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param int max_item_count: Max number of items to be returned in the enumeration operation. :param bool populate_query_metrics: Enable returning query metrics in response headers. :keyword str session_token: Token for use with Session consistency. @@ -375,10 +370,7 @@ def query_databases( **kwargs # type: Any ): # type: (...) -> Iterable[Dict[str, Any]] - """ - Query the databases in a Cosmos DB SQL database account. - - See aka.ms/{} for a full list of optional request and feed keyword arguments. + """Query the databases in a Cosmos DB SQL database account. :param str query: The Azure Cosmos DB SQL query to execute. :param list[str] parameters: Optional array of parameters to the query. Ignored if no query is provided. @@ -423,10 +415,7 @@ def delete_database( **kwargs # type: Any ): # type: (...) -> None - """ - Delete the database with the given ID (name). - - See aka.ms/{} for a full list of optional request and feed keyword arguments. + """Delete the database with the given ID (name). :param database: The ID (name), dict representing the properties or :class:`DatabaseProxy` instance of the database to delete. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py index 1f5cc7ace975..b4196cb1ae6e 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/database.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/database.py @@ -116,8 +116,6 @@ def read(self, populate_query_metrics=None, **kwargs): # type: (Optional[bool], Any) -> Dict[str, Any] """Read the database properties. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param bool populate_query_metrics: Enable returning query metrics in response headers. :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. @@ -160,7 +158,6 @@ def create_container( """Create a new container with the given ID (name). If a container with the given ID already exists, a CosmosResourceExistsError is raised. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of container to create. :param partition_key: The partition key to use for the container. @@ -245,7 +242,6 @@ def create_container_if_not_exists( If the container already exists, the existing settings are returned. Note: it does not check or update the existing container settings or offer throughput if they differ from what was passed into the method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param id: ID (name) of container to read or create. :param partition_key: The partition key to use for the container. @@ -295,8 +291,6 @@ def delete_container( # type: (...) -> None """Delete the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param container: The ID (name) of the container to delete. You can either pass in the ID of the container to delete, a :class:`ContainerProxy` instance or a dict representing the properties of the container. @@ -352,8 +346,6 @@ def list_containers(self, max_item_count=None, populate_query_metrics=None, **kw # type: (Optional[int], Optional[bool], Any) -> Iterable[Dict[str, Any]] """List the containers in the database. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of items to be returned in the enumeration operation. :param populate_query_metrics: Enable returning query metrics in response headers. :keyword str session_token: Token for use with Session consistency. @@ -398,8 +390,6 @@ def query_containers( # type: (...) -> Iterable[Dict[str, Any]] """List properties for containers in the current database. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. @@ -443,7 +433,6 @@ def replace_container( Property changes are persisted immediately. Any properties not specified will be reset to their default values. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param container: The ID (name), dict representing the properties or :class:`ContainerProxy` instance of the container to be replaced. @@ -509,8 +498,6 @@ def list_users(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] """List all users in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of users to be returned in the enumeration operation. :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of user properties (dicts). @@ -533,8 +520,6 @@ def query_users(self, query, parameters=None, max_item_count=None, **kwargs): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] """Return all users matching the given `query`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of users to be returned in the enumeration operation. @@ -582,7 +567,6 @@ def create_user(self, body, **kwargs): """Create a user in the container. To update or replace an existing user, use the :func:`ContainerProxy.upsert_user` method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object with an `id` key and value representing the user to be created. The user ID must be unique within the database, and consist of no more than 255 characters. @@ -620,7 +604,6 @@ def upsert_user(self, body, **kwargs): """Insert or update the specified user. If the user already exists in the container, it is replaced. If it does not, it is inserted. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the user to update or insert. :keyword Callable response_hook: A callable invoked with the response metadata. @@ -652,8 +635,6 @@ def replace_user( # type: (...) -> UserProxy """Replaces the specified user if it exists in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be replaced. :param body: A dict-like object representing the user to replace. @@ -685,8 +666,6 @@ def delete_user(self, user, **kwargs): # type: (Union[str, UserProxy, Dict[str, Any]], Any) -> None """Delete the specified user from the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param user: The ID (name), dict representing the properties or :class:`UserProxy` instance of the user to be deleted. :keyword Callable response_hook: A callable invoked with the response metadata. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py b/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py index f00faba78e0c..c570661d9f7d 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/scripts.py @@ -62,8 +62,6 @@ def list_stored_procedures(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] """List all stored procedures in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param int max_item_count: Max number of items to be returned in the enumeration operation. :returns: An Iterable of stored procedures (dicts). :rtype: Iterable[dict[str, Any]] @@ -80,8 +78,6 @@ def query_stored_procedures(self, query, parameters=None, max_item_count=None, * # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] """Return all stored procedures matching the given `query`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. @@ -103,8 +99,6 @@ def get_stored_procedure(self, sproc, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> Dict[str, Any] """Get the stored procedure identified by `id`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param sproc: The ID (name) or dict representing stored procedure to retrieve. :returns: A dict representing the retrieved stored procedure. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given stored procedure couldn't be retrieved. @@ -121,7 +115,6 @@ def create_stored_procedure(self, body, **kwargs): """Create a stored procedure in the container. To replace an existing sproc, use the :func:`Container.scripts.replace_stored_procedure` method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the sproc to create. :returns: A dict representing the new stored procedure. @@ -138,8 +131,6 @@ def replace_stored_procedure(self, sproc, body, **kwargs): # type: (Union[str, Dict[str, Any]], Dict[str, Any], Any) -> Dict[str, Any] """Replaces the specified stored procedure if it exists in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param sproc: The ID (name) or dict representing stored procedure to be replaced. :param body: A dict-like object representing the sproc to replace. :returns: A dict representing the stored procedure after replace went through. @@ -160,8 +151,6 @@ def delete_stored_procedure(self, sproc, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> None """Delete the specified stored procedure from the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param sproc: The ID (name) or dict representing stored procedure to be deleted. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The sproc wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The sproc does not exist in the container. @@ -184,8 +173,6 @@ def execute_stored_procedure( # type: (...) -> Any """Execute the specified stored procedure. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param sproc: The ID (name) or dict representing stored procedure to be executed. :param partition_key: Specifies the partition key to indicate which partition the sproc should execute on. :param params: List of parameters to be passed to the stored procedure to be executed. @@ -217,8 +204,6 @@ def list_triggers(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] """List all triggers in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of items to be returned in the enumeration operation. :returns: An Iterable of triggers (dicts). :rtype: Iterable[dict[str, Any]] @@ -235,8 +220,6 @@ def query_triggers(self, query, parameters=None, max_item_count=None, **kwargs): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] """Return all triggers matching the given `query`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of items to be returned in the enumeration operation. @@ -258,8 +241,6 @@ def get_trigger(self, trigger, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> Dict[str, Any] """Get the trigger identified by `id`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param trigger: The ID (name) or dict representing trigger to retrieve. :returns: A dict representing the retrieved trigger. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given trigger couldn't be retrieved. @@ -276,7 +257,6 @@ def create_trigger(self, body, **kwargs): """Create a trigger in the container. To replace an existing trigger, use the :func:`ContainerProxy.scripts.replace_trigger` method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the trigger to create. :returns: A dict representing the new trigger. @@ -293,8 +273,6 @@ def replace_trigger(self, trigger, body, **kwargs): # type: (Union[str, Dict[str, Any]], Dict[str, Any], Any) -> Dict[str, Any] """Replaces the specified tigger if it exists in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param trigger: The ID (name) or dict representing trigger to be replaced. :param body: A dict-like object representing the trigger to replace. :returns: A dict representing the trigger after replace went through. @@ -315,8 +293,6 @@ def delete_trigger(self, trigger, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> None """Delete the specified trigger from the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param trigger: The ID (name) or dict representing trigger to be deleted. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The trigger wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The trigger does not exist in the container. @@ -332,8 +308,6 @@ def list_user_defined_functions(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] """List all user defined functions in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of items to be returned in the enumeration operation. :returns: An Iterable of user defined functions (dicts). :rtype: Iterable[dict[str, Any]] @@ -348,10 +322,7 @@ def list_user_defined_functions(self, max_item_count=None, **kwargs): def query_user_defined_functions(self, query, parameters=None, max_item_count=None, **kwargs): # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] - """ - Return all user defined functions matching the given `query`. - - See aka.ms/{} for a full list of optional request and feed keyword arguments. + """Return all user defined functions matching the given `query`. :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. @@ -374,8 +345,6 @@ def get_user_defined_function(self, udf, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> Dict[str, Any] """Get the stored procedure identified by `id`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param udf: The ID (name) or dict representing udf to retrieve. :returns: A dict representing the retrieved user defined function. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the user defined function couldn't be retrieved. @@ -392,7 +361,6 @@ def create_user_defined_function(self, body, **kwargs): """Create a user defined function in the container. To replace an existing udf, use the :func:`ContainerProxy.scripts.replace_user_defined_function` method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the udf to create. :returns: A dict representing the new user defined function. @@ -409,8 +377,6 @@ def replace_user_defined_function(self, udf, body, **kwargs): # type: (Union[str, Dict[str, Any]], Dict[str, Any], Any) -> Dict[str, Any] """Replaces the specified user defined function if it exists in the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param udf: The ID (name) or dict representing udf to be replaced. :param body: A dict-like object representing the udf to replace. :returns: A dict representing the user defined function after replace went through. @@ -431,8 +397,6 @@ def delete_user_defined_function(self, udf, **kwargs): # type: (Union[str, Dict[str, Any]], Any) -> None """Delete the specified user defined function from the container. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param udf: The ID (name) or dict representing udf to be deleted. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The udf wasn't deleted successfully. :raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The UDF does not exist in the container. diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/user.py b/sdk/cosmos/azure-cosmos/azure/cosmos/user.py index a92c08397151..fe3221e7fb73 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/user.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/user.py @@ -72,8 +72,6 @@ def read(self, **kwargs): # type: (Any) -> Dict[str, Any] """Read user propertes. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :keyword Callable response_hook: A callable invoked with the response metadata. :returns: A dictionary of the retrieved user properties. :raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user couldn't be retrieved. @@ -94,8 +92,6 @@ def list_permissions(self, max_item_count=None, **kwargs): # type: (Optional[int], Any) -> Iterable[Dict[str, Any]] """List all permission for the user. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param max_item_count: Max number of permissions to be returned in the enumeration operation. :keyword Callable response_hook: A callable invoked with the response metadata. :returns: An Iterable of permissions (dicts). @@ -124,8 +120,6 @@ def query_permissions( # type: (str, Optional[List[str]], Optional[int], Any) -> Iterable[Dict[str, Any]] """Return all permissions matching the given `query`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param query: The Azure Cosmos DB SQL query to execute. :param parameters: Optional array of parameters to the query. Ignored if no query is provided. :param max_item_count: Max number of permissions to be returned in the enumeration operation. @@ -155,8 +149,6 @@ def get_permission(self, permission, **kwargs): # type: (str, Any) -> Permission """Get the permission identified by `id`. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be retrieved. :keyword Callable response_hook: A callable invoked with the response metadata. @@ -188,7 +180,6 @@ def create_permission(self, body, **kwargs): """Create a permission for the user. To update or replace an existing permision, use the :func:`UserProxy.upsert_permission` method. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the permission to create. :keyword Callable response_hook: A callable invoked with the response metadata. @@ -220,7 +211,6 @@ def upsert_permission(self, body, **kwargs): """Insert or update the specified permission. If the permission already exists in the container, it is replaced. If it does not, it is inserted. - See aka.ms/{} for a full list of optional request and feed keyword arguments. :param body: A dict-like object representing the permission to update or insert. :param Callable response_hook: A callable invoked with the response metadata. @@ -251,8 +241,6 @@ def replace_permission(self, permission, body, **kwargs): # type: (str, Dict[str, Any], Any) -> Permission """Replaces the specified permission if it exists for the user. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be replaced. :param body: A dict-like object representing the permission to replace. @@ -285,8 +273,6 @@ def delete_permission(self, permission, **kwargs): # type: (str, Any) -> None """Delete the specified permission from the user. - See aka.ms/{} for a full list of optional request and feed keyword arguments. - :param permission: The ID (name), dict representing the properties or :class:`Permission` instance of the permission to be replaced. :keyword Callable response_hook: A callable invoked with the response metadata. From 49c3c14d439e1a1a5370bf32f1679e961ddaa8f9 Mon Sep 17 00:00:00 2001 From: antisch Date: Wed, 30 Oct 2019 08:47:13 -0700 Subject: [PATCH 08/12] Fix samples merge --- .../samples/change_feed_management.py | 10 +++---- .../samples/collection_management.py | 26 +++++++++---------- .../samples/database_management.py | 10 +++---- .../samples/document_management.py | 10 +++---- .../nonpartitioned_collection_operations.py | 10 +++---- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/samples/change_feed_management.py b/sdk/cosmos/azure-cosmos/samples/change_feed_management.py index b753dc058424..42427fb3dce7 100644 --- a/sdk/cosmos/azure-cosmos/samples/change_feed_management.py +++ b/sdk/cosmos/azure-cosmos/samples/change_feed_management.py @@ -1,6 +1,6 @@ import azure.cosmos.documents as documents import azure.cosmos.cosmos_client as cosmos_client -import azure.cosmos.errors as errors +import azure.cosmos.exceptions as exceptions import azure.cosmos.partition_key as partition_key import datetime import uuid @@ -60,7 +60,7 @@ def run_sample(): # setup database for this sample try: db = client.create_database(id=DATABASE_ID) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: raise RuntimeError("Database with id '{}' already exists".format(DATABASE_ID)) # setup container for this sample @@ -71,7 +71,7 @@ def run_sample(): ) print('Container with id \'{0}\' created'.format(CONTAINER_ID)) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: raise RuntimeError("Container with id '{}' already exists".format(CONTAINER_ID)) create_items(container, 100) @@ -80,10 +80,10 @@ def run_sample(): # cleanup database after sample try: client.delete_database(db) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: pass - except errors.CosmosHttpResponseError as e: + except exceptions.CosmosHttpResponseError as e: print('\nrun_sample has caught an error. {0}'.format(e.message)) finally: diff --git a/sdk/cosmos/azure-cosmos/samples/collection_management.py b/sdk/cosmos/azure-cosmos/samples/collection_management.py index a4a5821e3bb7..326fc8a6f1b8 100644 --- a/sdk/cosmos/azure-cosmos/samples/collection_management.py +++ b/sdk/cosmos/azure-cosmos/samples/collection_management.py @@ -1,5 +1,5 @@ import azure.cosmos.cosmos_client as cosmos_client -import azure.cosmos.errors as errors +import azure.cosmos.exceptions as exceptions from azure.cosmos.partition_key import PartitionKey import config @@ -77,7 +77,7 @@ def create_container(db, id): db.create_container(id=id, partition_key=partition_key) print('Container with id \'{0}\' created'.format(id)) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'{0}\' already exists'.format(id)) print("\n2.2 Create Container - With custom index policy") @@ -101,7 +101,7 @@ def create_container(db, id): print('IndexPolicy Mode - \'{0}\''.format(properties['indexingPolicy']['indexingMode'])) print('IndexPolicy Automatic - \'{0}\''.format(properties['indexingPolicy']['automatic'])) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'{0}\' already exists'.format(coll['id'])) print("\n2.3 Create Container - With custom offer throughput") @@ -115,7 +115,7 @@ def create_container(db, id): ) print('Container with id \'{0}\' created'.format(container.id)) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'{0}\' already exists'.format(coll['id'])) print("\n2.4 Create Container - With Unique keys") @@ -131,7 +131,7 @@ def create_container(db, id): print('Container with id \'{0}\' created'.format(container.id)) print('Unique Key Paths - \'{0}\', \'{1}\''.format(unique_key_paths[0], unique_key_paths[1])) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'container_unique_keys\' already exists') print("\n2.5 Create Collection - With Partition key V2 (Default)") @@ -145,7 +145,7 @@ def create_container(db, id): print('Container with id \'{0}\' created'.format(container.id)) print('Partition Key - \'{0}\''.format(properties['partitionKey'])) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'collection_partition_key_v2\' already exists') print("\n2.6 Create Collection - With Partition key V1") @@ -159,7 +159,7 @@ def create_container(db, id): print('Container with id \'{0}\' created'.format(container.id)) print('Partition Key - \'{0}\''.format(properties['partitionKey'])) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'collection_partition_key_v1\' already exists') @@ -180,7 +180,7 @@ def manage_offer_throughput(db, id): print('Found Offer \'{0}\' for Container \'{1}\' and its throughput is \'{2}\''.format(offer.properties['id'], container.id, offer.properties['content']['offerThroughput'])) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A container with id \'{0}\' does not exist'.format(id)) print("\n3.2 Change Offer Throughput of Container") @@ -199,7 +199,7 @@ def read_Container(db, id): container = db.get_container_client(id) print('Container with id \'{0}\' was found, it\'s link is {1}'.format(container.id, container.container_link)) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: print('A container with id \'{0}\' does not exist'.format(id)) @@ -225,7 +225,7 @@ def delete_Container(db, id): print('Container with id \'{0}\' was deleted'.format(id)) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: print('A container with id \'{0}\' does not exist'.format(id)) @@ -237,7 +237,7 @@ def run_sample(): try: db = client.create_database(id=DATABASE_ID) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: db = client.get_database_client(DATABASE_ID) # query for a container @@ -262,10 +262,10 @@ def run_sample(): try: client.delete_database(db) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: pass - except errors.CosmosHttpResponseError as e: + except exceptions.CosmosHttpResponseError as e: print('\nrun_sample has caught an error. {0}'.format(e.message)) finally: diff --git a/sdk/cosmos/azure-cosmos/samples/database_management.py b/sdk/cosmos/azure-cosmos/samples/database_management.py index c62d249e7427..26645a6f1a08 100644 --- a/sdk/cosmos/azure-cosmos/samples/database_management.py +++ b/sdk/cosmos/azure-cosmos/samples/database_management.py @@ -1,5 +1,5 @@ import azure.cosmos.cosmos_client as cosmos_client -import azure.cosmos.errors as errors +import azure.cosmos.exceptions as exceptions import config @@ -52,7 +52,7 @@ def create_database(client, id): client.create_database(id=id) print('Database with id \'{0}\' created'.format(id)) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('A database with id \'{0}\' already exists'.format(id)) @@ -63,7 +63,7 @@ def read_database(client, id): database = client.get_database_client(id) print('Database with id \'{0}\' was found, it\'s link is {1}'.format(id, database.database_link)) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: print('A database with id \'{0}\' does not exist'.format(id)) @@ -89,7 +89,7 @@ def delete_database(client, id): print('Database with id \'{0}\' was deleted'.format(id)) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: print('A database with id \'{0}\' does not exist'.format(id)) @@ -111,7 +111,7 @@ def run_sample(): # delete database by id delete_database(client, DATABASE_ID) - except errors.CosmosHttpResponseError as e: + except exceptions.CosmosHttpResponseError as e: print('\nrun_sample has caught an error. {0}'.format(e.message)) finally: diff --git a/sdk/cosmos/azure-cosmos/samples/document_management.py b/sdk/cosmos/azure-cosmos/samples/document_management.py index 4a627ee6a9c1..82f36d40852d 100644 --- a/sdk/cosmos/azure-cosmos/samples/document_management.py +++ b/sdk/cosmos/azure-cosmos/samples/document_management.py @@ -1,5 +1,5 @@ import azure.cosmos.cosmos_client as cosmos_client -import azure.cosmos.errors as errors +import azure.cosmos.exceptions as exceptions from azure.cosmos.partition_key import PartitionKey import datetime @@ -163,7 +163,7 @@ def run_sample(): try: db = client.create_database(id=DATABASE_ID) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: pass # setup container for this sample @@ -171,7 +171,7 @@ def run_sample(): container = db.create_container(id=CONTAINER_ID, partition_key=PartitionKey(path='/id', kind='Hash')) print('Container with id \'{0}\' created'.format(CONTAINER_ID)) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('Container with id \'{0}\' was found'.format(CONTAINER_ID)) create_items(container) @@ -186,10 +186,10 @@ def run_sample(): try: client.delete_database(db) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: pass - except errors.CosmosHttpResponseError as e: + except exceptions.CosmosHttpResponseError as e: print('\nrun_sample has caught an error. {0}'.format(e.message)) finally: diff --git a/sdk/cosmos/azure-cosmos/samples/nonpartitioned_collection_operations.py b/sdk/cosmos/azure-cosmos/samples/nonpartitioned_collection_operations.py index f7532bdcc2bb..9d57e2e83360 100644 --- a/sdk/cosmos/azure-cosmos/samples/nonpartitioned_collection_operations.py +++ b/sdk/cosmos/azure-cosmos/samples/nonpartitioned_collection_operations.py @@ -20,7 +20,7 @@ #SOFTWARE. import azure.cosmos.cosmos_client as cosmos_client -import azure.cosmos.errors as errors +import azure.cosmos.exceptions as exceptions import requests import six import json @@ -268,7 +268,7 @@ def run_sample(): # setup database for this sample try: db = client.create_database(id=DATABASE_ID) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: db = client.get_database_client(DATABASE_ID) # setup container for this sample @@ -276,7 +276,7 @@ def run_sample(): container, document = create_nonpartitioned_collection(db) print('Container with id \'{0}\' created'.format(CONTAINER_ID)) - except errors.CosmosResourceExistsError: + except exceptions.CosmosResourceExistsError: print('Container with id \'{0}\' was found'.format(CONTAINER_ID)) # Read Item created in non partitioned collection using older API version @@ -291,10 +291,10 @@ def run_sample(): # cleanup database after sample try: client.delete_database(db) - except errors.CosmosResourceNotFoundError: + except exceptions.CosmosResourceNotFoundError: pass - except errors.CosmosHttpResponseError as e: + except exceptions.CosmosHttpResponseError as e: print('\nrun_sample has caught an error. {0}'.format(e.message)) finally: From f51abb1d109ccd2bd4a2cb459e38d19cf1b86ba8 Mon Sep 17 00:00:00 2001 From: antisch Date: Wed, 30 Oct 2019 09:34:52 -0700 Subject: [PATCH 09/12] Updated conditional param parsing --- sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py index 355cd1a1ae11..650f8e7feb15 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py @@ -72,26 +72,26 @@ 'query_version': 'queryVersion' } -def _get_match_headers(kwargs, match_param, etag_param): - # type: (str) -> Tuple(Dict[str, Any], Optional[str], Optional[str]) +def _get_match_headers(kwargs): + # type: (str) -> Tuple(Dict[str, Any]) if_match = kwargs.pop('if_match', None) if_none_match = kwargs.pop('if_none_match', None) - match_condition = kwargs.pop(match_param, None) + match_condition = kwargs.pop('match_condition', None) if match_condition == MatchConditions.IfNotModified: - if_match = kwargs.pop(etag_param, None) + if_match = kwargs.pop('etag', None) if not if_match: - raise ValueError("'{}' specified without '{}'.".format(match_param, etag_param)) + raise ValueError("'match_condition' specified without 'etag'.") elif match_condition == MatchConditions.IfPresent: if_match = '*' elif match_condition == MatchConditions.IfModified: - if_none_match = kwargs.pop(etag_param, None) + if_none_match = kwargs.pop('etag', None) if not if_none_match: - raise ValueError("'{}' specified without '{}'.".format(match_param, etag_param)) + raise ValueError("'match_condition' specified without 'etag'.") elif match_condition == MatchConditions.IfMissing: if_none_match = '*' elif match_condition is None: - if etag_param in kwargs: - raise ValueError("'{}' specified without '{}'.".format(etag_param, match_param)) + if 'etag' in kwargs: + raise ValueError("'etag' specified without 'match_condition'.") else: raise TypeError("Invalid match condition: {}".format(match_condition)) return if_match, if_none_match @@ -104,7 +104,7 @@ def build_options(kwargs): if key in kwargs: options[value] = kwargs.pop(key) - if_match, if_none_match = _get_match_headers(kwargs, 'match_condition', 'etag') + if_match, if_none_match = _get_match_headers(kwargs) if if_match: options['accessCondition'] = {'type': 'IfMatch', 'condition': if_match} if if_none_match: From 9f0e75cb23d4e16cabcbd51ac6b267c7be9a56f2 Mon Sep 17 00:00:00 2001 From: antisch Date: Wed, 30 Oct 2019 09:36:36 -0700 Subject: [PATCH 10/12] Fixed type hint --- sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py index 650f8e7feb15..5b866e541158 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py @@ -73,7 +73,7 @@ } def _get_match_headers(kwargs): - # type: (str) -> Tuple(Dict[str, Any]) + # type: (Dict[str, Any]) -> Tuple(Optional[str], Optional[str]) if_match = kwargs.pop('if_match', None) if_none_match = kwargs.pop('if_none_match', None) match_condition = kwargs.pop('match_condition', None) From 87f0037c84d4244a71ec4244c1388dd853f65181 Mon Sep 17 00:00:00 2001 From: antisch Date: Wed, 30 Oct 2019 12:38:59 -0700 Subject: [PATCH 11/12] Removed samples init --- sdk/cosmos/azure-cosmos/samples/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos/samples/__init__.py diff --git a/sdk/cosmos/azure-cosmos/samples/__init__.py b/sdk/cosmos/azure-cosmos/samples/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 From e6ad34bc372d76c52e65c6851b3f8e729a674507 Mon Sep 17 00:00:00 2001 From: antisch Date: Wed, 30 Oct 2019 13:47:29 -0700 Subject: [PATCH 12/12] Added match condition validation tests --- sdk/cosmos/azure-cosmos/test/crud_tests.py | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sdk/cosmos/azure-cosmos/test/crud_tests.py b/sdk/cosmos/azure-cosmos/test/crud_tests.py index ae28b57da98e..c9620430c8a5 100644 --- a/sdk/cosmos/azure-cosmos/test/crud_tests.py +++ b/sdk/cosmos/azure-cosmos/test/crud_tests.py @@ -858,6 +858,36 @@ def test_document_crud(self): if_match=old_etag, ) + # should fail if only etag specified + with self.assertRaises(ValueError): + created_collection.replace_item( + etag=replaced_document['_etag'], + item=replaced_document['id'], + body=replaced_document + ) + + # should fail if only match condition specified + with self.assertRaises(ValueError): + created_collection.replace_item( + match_condition=MatchConditions.IfNotModified, + item=replaced_document['id'], + body=replaced_document + ) + with self.assertRaises(ValueError): + created_collection.replace_item( + match_condition=MatchConditions.IfModified, + item=replaced_document['id'], + body=replaced_document + ) + + # should fail if invalid match condition specified + with self.assertRaises(TypeError): + created_collection.replace_item( + match_condition=replaced_document['_etag'], + item=replaced_document['id'], + body=replaced_document + ) + # should pass for most recent etag replaced_document_conditional = created_collection.replace_item( match_condition=MatchConditions.IfNotModified,