Skip to content

Commit acd6945

Browse files
simorenohannatischgahl-levytjprescott
authored
[Cosmos] mark populate_query_metrics flag to be deleted when used and 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 <[email protected]> * 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 <[email protected]> * closing python code snippet * last doc updates * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Simon Moreno <[email protected]> * 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 <[email protected]> Co-authored-by: Gahl Levy <[email protected]> Co-authored-by: Travis Prescott <[email protected]>
1 parent 8c4b715 commit acd6945

File tree

5 files changed

+204
-24
lines changed

5 files changed

+204
-24
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Method call will now require an 'id' field to be present in the document body.
1111
- Marked the GetAuthorizationHeader method for deprecation since it will no longer be public in a future release.
1212
- Added samples showing how to configure retry options for both the sync and async clients.
1313
- Deprecated the `connection_retry_policy` and `retry_options` options in the sync client.
14+
- Added user warning to non-query methods trying to use `populate_query_metrics` options.
1415

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

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

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"""Create, read, update and delete items in the Azure Cosmos DB SQL API service.
2323
"""
2424

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

27+
28+
import warnings
2729
from azure.core.tracing.decorator import distributed_trace # type: ignore
2830

2931
from ._cosmos_client_connection import CosmosClientConnection
@@ -108,21 +110,29 @@ def _set_partition_key(self, partition_key):
108110
return CosmosClientConnection._return_undefined_or_empty_partition_key(self.is_system_key)
109111
return partition_key
110112

113+
@overload
114+
def read(
115+
self,
116+
*,
117+
populate_partition_key_range_statistics: Optional[bool] = None,
118+
populate_quota_info: Optional[bool] = None,
119+
**kwargs
120+
):
121+
...
122+
123+
111124
@distributed_trace
112125
def read(
113126
self,
114-
populate_query_metrics=None, # type: Optional[bool]
115-
populate_partition_key_range_statistics=None, # type: Optional[bool]
116-
populate_quota_info=None, # type: Optional[bool]
127+
*args,
117128
**kwargs # type: Any
118129
):
119130
# type: (...) -> Dict[str, Any]
120131
"""Read the container properties.
121132
122-
:param populate_query_metrics: Enable returning query metrics in response headers.
123-
:param populate_partition_key_range_statistics: Enable returning partition key
133+
:keyword bool populate_partition_key_range_statistics: Enable returning partition key
124134
range statistics in response headers.
125-
:param populate_quota_info: Enable returning collection storage quota information in response headers.
135+
:keyword bool populate_quota_info: Enable returning collection storage quota information in response headers.
126136
:keyword str session_token: Token for use with Session consistency.
127137
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
128138
:keyword Callable response_hook: A callable invoked with the response metadata.
@@ -133,8 +143,15 @@ def read(
133143
"""
134144
request_options = build_options(kwargs)
135145
response_hook = kwargs.pop('response_hook', None)
136-
if populate_query_metrics is not None:
137-
request_options["populateQueryMetrics"] = populate_query_metrics
146+
populate_query_metrics = args[0] if args else kwargs.pop('populate_query_metrics', None)
147+
if populate_query_metrics:
148+
warnings.warn(
149+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
150+
UserWarning,
151+
)
152+
populate_partition_key_range_statistics = args[1] if args and len(args) > 0 else kwargs.pop(
153+
"populate_partition_key_range_statistics", None)
154+
populate_quota_info = args[2] if args and len(args) > 1 else kwargs.pop("populate_quota_info", None)
138155
if populate_partition_key_range_statistics is not None:
139156
request_options["populatePartitionKeyRangeStatistics"] = populate_partition_key_range_statistics
140157
if populate_quota_info is not None:
@@ -164,7 +181,6 @@ def read_item(
164181
165182
:param item: The ID (name) or dict representing item to retrieve.
166183
:param partition_key: Partition key for the item to retrieve.
167-
:param populate_query_metrics: Enable returning query metrics in response headers.
168184
:param post_trigger_include: trigger id to be used as post operation trigger.
169185
:keyword str session_token: Token for use with Session consistency.
170186
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
@@ -195,6 +211,10 @@ def read_item(
195211
if partition_key is not None:
196212
request_options["partitionKey"] = self._set_partition_key(partition_key)
197213
if populate_query_metrics is not None:
214+
warnings.warn(
215+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
216+
UserWarning,
217+
)
198218
request_options["populateQueryMetrics"] = populate_query_metrics
199219
if post_trigger_include is not None:
200220
request_options["postTriggerInclude"] = post_trigger_include
@@ -219,7 +239,6 @@ def read_all_items(
219239
"""List all the items in the container.
220240
221241
:param max_item_count: Max number of items to be returned in the enumeration operation.
222-
:param populate_query_metrics: Enable returning query metrics in response headers.
223242
:keyword str session_token: Token for use with Session consistency.
224243
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
225244
:keyword Callable response_hook: A callable invoked with the response metadata.
@@ -236,6 +255,10 @@ def read_all_items(
236255
if max_item_count is not None:
237256
feed_options["maxItemCount"] = max_item_count
238257
if populate_query_metrics is not None:
258+
warnings.warn(
259+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
260+
UserWarning,
261+
)
239262
feed_options["populateQueryMetrics"] = populate_query_metrics
240263
max_integrated_cache_staleness_in_ms = kwargs.pop('max_integrated_cache_staleness_in_ms', None)
241264
if max_integrated_cache_staleness_in_ms:
@@ -409,7 +432,6 @@ def replace_item(
409432
410433
:param item: The ID (name) or dict representing item to be replaced.
411434
:param body: A dict-like object representing the item to replace.
412-
:param populate_query_metrics: Enable returning query metrics in response headers.
413435
:param pre_trigger_include: trigger id to be used as pre operation trigger.
414436
:param post_trigger_include: trigger id to be used as post operation trigger.
415437
:keyword str session_token: Token for use with Session consistency.
@@ -428,6 +450,10 @@ def replace_item(
428450
response_hook = kwargs.pop('response_hook', None)
429451
request_options["disableAutomaticIdGeneration"] = True
430452
if populate_query_metrics is not None:
453+
warnings.warn(
454+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
455+
UserWarning,
456+
)
431457
request_options["populateQueryMetrics"] = populate_query_metrics
432458
if pre_trigger_include is not None:
433459
request_options["preTriggerInclude"] = pre_trigger_include
@@ -457,7 +483,6 @@ def upsert_item(
457483
does not already exist, it is inserted.
458484
459485
:param body: A dict-like object representing the item to update or insert.
460-
:param populate_query_metrics: Enable returning query metrics in response headers.
461486
:param pre_trigger_include: trigger id to be used as pre operation trigger.
462487
:param post_trigger_include: trigger id to be used as post operation trigger.
463488
:keyword str session_token: Token for use with Session consistency.
@@ -474,6 +499,10 @@ def upsert_item(
474499
response_hook = kwargs.pop('response_hook', None)
475500
request_options["disableAutomaticIdGeneration"] = True
476501
if populate_query_metrics is not None:
502+
warnings.warn(
503+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
504+
UserWarning,
505+
)
477506
request_options["populateQueryMetrics"] = populate_query_metrics
478507
if pre_trigger_include is not None:
479508
request_options["preTriggerInclude"] = pre_trigger_include
@@ -507,7 +536,6 @@ def create_item(
507536
:func:`ContainerProxy.upsert_item` method.
508537
509538
:param body: A dict-like object representing the item to create.
510-
:param populate_query_metrics: Enable returning query metrics in response headers.
511539
:param pre_trigger_include: trigger id to be used as pre operation trigger.
512540
:param post_trigger_include: trigger id to be used as post operation trigger.
513541
:param indexing_directive: Indicate whether the document should be omitted from indexing.
@@ -527,6 +555,10 @@ def create_item(
527555

528556
request_options["disableAutomaticIdGeneration"] = not kwargs.pop('enable_automatic_id_generation', False)
529557
if populate_query_metrics:
558+
warnings.warn(
559+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
560+
UserWarning,
561+
)
530562
request_options["populateQueryMetrics"] = populate_query_metrics
531563
if pre_trigger_include is not None:
532564
request_options["preTriggerInclude"] = pre_trigger_include
@@ -559,7 +591,6 @@ def delete_item(
559591
560592
:param item: The ID (name) or dict representing item to be deleted.
561593
:param partition_key: Specifies the partition key value for the item.
562-
:param populate_query_metrics: Enable returning query metrics in response headers.
563594
:param pre_trigger_include: trigger id to be used as pre operation trigger.
564595
:param post_trigger_include: trigger id to be used as post operation trigger.
565596
:keyword str session_token: Token for use with Session consistency.
@@ -577,6 +608,10 @@ def delete_item(
577608
if partition_key is not None:
578609
request_options["partitionKey"] = self._set_partition_key(partition_key)
579610
if populate_query_metrics is not None:
611+
warnings.warn(
612+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
613+
UserWarning,
614+
)
580615
request_options["populateQueryMetrics"] = populate_query_metrics
581616
if pre_trigger_include is not None:
582617
request_options["preTriggerInclude"] = pre_trigger_include

sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ def create_database( # pylint: disable=redefined-builtin
238238
Create a new database with the given ID (name).
239239
240240
:param id: ID (name) of the database to create.
241-
:param bool populate_query_metrics: Enable returning query metrics in response headers.
242241
:param int offer_throughput: The provisioned throughput for this offer.
243242
:keyword str session_token: Token for use with Session consistency.
244243
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
@@ -264,6 +263,10 @@ def create_database( # pylint: disable=redefined-builtin
264263
request_options = build_options(kwargs)
265264
response_hook = kwargs.pop('response_hook', None)
266265
if populate_query_metrics is not None:
266+
warnings.warn(
267+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
268+
UserWarning,
269+
)
267270
request_options["populateQueryMetrics"] = populate_query_metrics
268271
if offer_throughput is not None:
269272
request_options["offerThroughput"] = offer_throughput
@@ -350,7 +353,6 @@ def list_databases(
350353
"""List the databases in a Cosmos DB SQL database account.
351354
352355
:param int max_item_count: Max number of items to be returned in the enumeration operation.
353-
:param bool populate_query_metrics: Enable returning query metrics in response headers.
354356
:keyword str session_token: Token for use with Session consistency.
355357
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
356358
:keyword Callable response_hook: A callable invoked with the response metadata.
@@ -362,6 +364,10 @@ def list_databases(
362364
if max_item_count is not None:
363365
feed_options["maxItemCount"] = max_item_count
364366
if populate_query_metrics is not None:
367+
warnings.warn(
368+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
369+
UserWarning,
370+
)
365371
feed_options["populateQueryMetrics"] = populate_query_metrics
366372

367373
result = self.client_connection.ReadDatabases(options=feed_options, **kwargs)
@@ -387,7 +393,6 @@ def query_databases(
387393
:param bool enable_cross_partition_query: Allow scan on the queries which couldn't be
388394
served as indexing was opted out on the requested paths.
389395
:param int max_item_count: Max number of items to be returned in the enumeration operation.
390-
:param bool populate_query_metrics: Enable returning query metrics in response headers.
391396
:keyword str session_token: Token for use with Session consistency.
392397
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
393398
:keyword Callable response_hook: A callable invoked with the response metadata.
@@ -401,6 +406,10 @@ def query_databases(
401406
if max_item_count is not None:
402407
feed_options["maxItemCount"] = max_item_count
403408
if populate_query_metrics is not None:
409+
warnings.warn(
410+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
411+
UserWarning,
412+
)
404413
feed_options["populateQueryMetrics"] = populate_query_metrics
405414

406415
if query:
@@ -430,7 +439,6 @@ def delete_database(
430439
:param database: The ID (name), dict representing the properties or :class:`DatabaseProxy`
431440
instance of the database to delete.
432441
:type database: str or dict(str, str) or ~azure.cosmos.DatabaseProxy
433-
:param bool populate_query_metrics: Enable returning query metrics in response headers.
434442
:keyword str session_token: Token for use with Session consistency.
435443
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
436444
:keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource
@@ -443,6 +451,10 @@ def delete_database(
443451
request_options = build_options(kwargs)
444452
response_hook = kwargs.pop('response_hook', None)
445453
if populate_query_metrics is not None:
454+
warnings.warn(
455+
"the populate_query_metrics flag does not apply to this method and will be removed in the future",
456+
UserWarning,
457+
)
446458
request_options["populateQueryMetrics"] = populate_query_metrics
447459

448460
database_link = self._get_database_link(database)

0 commit comments

Comments
 (0)