Skip to content

Commit

Permalink
[Cosmos] mark populate_query_metrics flag to be deleted when used and…
Browse files Browse the repository at this point in the history
… remove docs (#22264)

* initial commit

* Client Constructor (#20310)

* Removed some stuff

* Looking at constructors

* Updated request

* Added client close

* working client creation

Co-authored-by: simorenoh <simonmorenohe@gmail.com>

* read database

database read works, but ignored exception is returned:
Fatal error on SSL transport
NoneType has no attribute 'send' (_loop._proactor.send)
RuntimeError: Event loop is closed
Unclosed connector/ connection

* Update simon_testfile.py

* with coroutine

Added methods needed to use async with when initializing client, but logs output "Exception ignored... Runtime Error: Event loop is closed"

* Update simon_testfile.py

* small changes

* async with returns no exceptions

* async read container

* async item read

* cleaning up

* create item/ database methods

* item delete working

* docs replace functionality

missing upsert and other resources

* upsert functionality

missing read_all_items and both query methods for container class

* missing query methods

* CRUD for udf, sproc, triggers

* initial query logic + container methods

* missing some execution logic and tests

* oops

* fully working queries

* small fix to query_items()

also fixed README and added examples_async

* Update _cosmos_client_connection_async.py

* Update _cosmos_client_connection.py

* documentation update

* updated MIT dates and get_user_client() description

* Update CHANGELOG.md

* Delete simon_testfile.py

* leftover retry utility

* Update README.md

* docs and removed six package

* changes based on comments

still missing discussion resolution on SSL verification and tests for async functionality under test module (apart from samples which are basically end to end tests)

* small change in type hints

* updated readme

* fixes based on conversations

* added missing type comments

* update changelog for ci pipeline

* added typehints, moved params into keywords, added decorators, made _connection_policy private

* changes based on sync with central sdk

* remove is_system_key from scripts (only used in execute_sproc)

is_system_key verifies that an empty partition key is properly dealt with if ['partitionKey']['systemKey'] exists in the container options - however, we do not allow containers to be created with empty partition key values in the python sdk, so the functionality is needless

* Revert "remove is_system_key from scripts (only used in execute_sproc)"

Reverting last commit, will find way to init is_system_key for now

* async script proxy using composition

* pylint

* capitalized constants

* Apply suggestions from code review

Clarifying comments for README

Co-authored-by: Gahl Levy <75269480+gahl-levy@users.noreply.github.com>

* closing python code snippet

* last doc updates

* Update sdk/cosmos/azure-cosmos/CHANGELOG.md

Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com>

* version update

* cosmos updates for release

* send user warning for use of populate_query_metrics flag

* Update CHANGELOG.md

* Update container.py

* added tests

* avoid index errors

* Update CHANGELOG.md

Co-authored-by: annatisch <antisch@microsoft.com>
Co-authored-by: Gahl Levy <75269480+gahl-levy@users.noreply.github.com>
Co-authored-by: Travis Prescott <tjprescott@users.noreply.github.com>
  • Loading branch information
4 people authored May 13, 2022
1 parent 8c4b715 commit acd6945
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 24 deletions.
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Method call will now require an 'id' field to be present in the document body.
- Marked the GetAuthorizationHeader method for deprecation since it will no longer be public in a future release.
- Added samples showing how to configure retry options for both the sync and async clients.
- Deprecated the `connection_retry_policy` and `retry_options` options in the sync client.
- Added user warning to non-query methods trying to use `populate_query_metrics` options.

### 4.3.0b4 (2022-04-07)

Expand Down
65 changes: 50 additions & 15 deletions sdk/cosmos/azure-cosmos/azure/cosmos/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"""Create, read, update and delete items in the Azure Cosmos DB SQL API service.
"""

from typing import Any, Dict, List, Optional, Union, Iterable, cast # pylint: disable=unused-import
from typing import Any, Dict, List, Optional, Union, Iterable, cast, overload # pylint: disable=unused-import


import warnings
from azure.core.tracing.decorator import distributed_trace # type: ignore

from ._cosmos_client_connection import CosmosClientConnection
Expand Down Expand Up @@ -108,21 +110,29 @@ def _set_partition_key(self, partition_key):
return CosmosClientConnection._return_undefined_or_empty_partition_key(self.is_system_key)
return partition_key

@overload
def read(
self,
*,
populate_partition_key_range_statistics: Optional[bool] = None,
populate_quota_info: Optional[bool] = None,
**kwargs
):
...


@distributed_trace
def read(
self,
populate_query_metrics=None, # type: Optional[bool]
populate_partition_key_range_statistics=None, # type: Optional[bool]
populate_quota_info=None, # type: Optional[bool]
*args,
**kwargs # type: Any
):
# type: (...) -> Dict[str, Any]
"""Read the container properties.
:param populate_query_metrics: Enable returning query metrics in response headers.
:param populate_partition_key_range_statistics: Enable returning partition key
:keyword bool 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 bool populate_quota_info: Enable returning collection storage quota information 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.
Expand All @@ -133,8 +143,15 @@ def read(
"""
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
if populate_query_metrics is not None:
request_options["populateQueryMetrics"] = populate_query_metrics
populate_query_metrics = args[0] if args else kwargs.pop('populate_query_metrics', None)
if populate_query_metrics:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
populate_partition_key_range_statistics = args[1] if args and len(args) > 0 else kwargs.pop(
"populate_partition_key_range_statistics", None)
populate_quota_info = args[2] if args and len(args) > 1 else kwargs.pop("populate_quota_info", None)
if populate_partition_key_range_statistics is not None:
request_options["populatePartitionKeyRangeStatistics"] = populate_partition_key_range_statistics
if populate_quota_info is not None:
Expand Down Expand Up @@ -164,7 +181,6 @@ def read_item(
: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.
:param post_trigger_include: trigger id to be used as post operation trigger.
: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.
Expand Down Expand Up @@ -195,6 +211,10 @@ def read_item(
if partition_key is not None:
request_options["partitionKey"] = self._set_partition_key(partition_key)
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics
if post_trigger_include is not None:
request_options["postTriggerInclude"] = post_trigger_include
Expand All @@ -219,7 +239,6 @@ def read_all_items(
"""List all the items in the container.
: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.
: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.
Expand All @@ -236,6 +255,10 @@ def read_all_items(
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
feed_options["populateQueryMetrics"] = populate_query_metrics
max_integrated_cache_staleness_in_ms = kwargs.pop('max_integrated_cache_staleness_in_ms', None)
if max_integrated_cache_staleness_in_ms:
Expand Down Expand Up @@ -409,7 +432,6 @@ def replace_item(
: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.
: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 str session_token: Token for use with Session consistency.
Expand All @@ -428,6 +450,10 @@ def replace_item(
response_hook = kwargs.pop('response_hook', None)
request_options["disableAutomaticIdGeneration"] = True
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics
if pre_trigger_include is not None:
request_options["preTriggerInclude"] = pre_trigger_include
Expand Down Expand Up @@ -457,7 +483,6 @@ def upsert_item(
does not already exist, it is inserted.
:param body: A dict-like object representing the item to update or insert.
: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 str session_token: Token for use with Session consistency.
Expand All @@ -474,6 +499,10 @@ def upsert_item(
response_hook = kwargs.pop('response_hook', None)
request_options["disableAutomaticIdGeneration"] = True
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics
if pre_trigger_include is not None:
request_options["preTriggerInclude"] = pre_trigger_include
Expand Down Expand Up @@ -507,7 +536,6 @@ def create_item(
:func:`ContainerProxy.upsert_item` method.
:param body: A dict-like object representing the item to create.
: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.
Expand All @@ -527,6 +555,10 @@ def create_item(

request_options["disableAutomaticIdGeneration"] = not kwargs.pop('enable_automatic_id_generation', False)
if populate_query_metrics:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics
if pre_trigger_include is not None:
request_options["preTriggerInclude"] = pre_trigger_include
Expand Down Expand Up @@ -559,7 +591,6 @@ def delete_item(
: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.
: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 str session_token: Token for use with Session consistency.
Expand All @@ -577,6 +608,10 @@ def delete_item(
if partition_key is not None:
request_options["partitionKey"] = self._set_partition_key(partition_key)
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics
if pre_trigger_include is not None:
request_options["preTriggerInclude"] = pre_trigger_include
Expand Down
20 changes: 16 additions & 4 deletions sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def create_database( # pylint: disable=redefined-builtin
Create a new database with the given ID (name).
: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.
: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.
Expand All @@ -264,6 +263,10 @@ def create_database( # pylint: disable=redefined-builtin
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics
if offer_throughput is not None:
request_options["offerThroughput"] = offer_throughput
Expand Down Expand Up @@ -350,7 +353,6 @@ def list_databases(
"""List the databases in a Cosmos DB SQL database account.
: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.
: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.
Expand All @@ -362,6 +364,10 @@ def list_databases(
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
feed_options["populateQueryMetrics"] = populate_query_metrics

result = self.client_connection.ReadDatabases(options=feed_options, **kwargs)
Expand All @@ -387,7 +393,6 @@ def query_databases(
: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 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.
Expand All @@ -401,6 +406,10 @@ def query_databases(
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
feed_options["populateQueryMetrics"] = populate_query_metrics

if query:
Expand Down Expand Up @@ -430,7 +439,6 @@ def delete_database(
: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 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 str etag: An ETag value, or the wildcard character (*). Used to check if the resource
Expand All @@ -443,6 +451,10 @@ def delete_database(
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
if populate_query_metrics is not None:
warnings.warn(
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
UserWarning,
)
request_options["populateQueryMetrics"] = populate_query_metrics

database_link = self._get_database_link(database)
Expand Down
Loading

0 comments on commit acd6945

Please sign in to comment.