Skip to content

Commit 85b15e3

Browse files
authored
async changes (#34019)
1 parent a780070 commit 85b15e3

File tree

6 files changed

+53
-112
lines changed

6 files changed

+53
-112
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ def _replace_throughput(
766766
max_throughput = throughput.auto_scale_max_throughput
767767
increment_percent = throughput.auto_scale_increment_percent
768768
if max_throughput is not None:
769-
new_throughput_properties['content']['offerAutopilotSettings'][
770-
'maxThroughput'] = max_throughput
769+
new_throughput_properties['content']['offerAutopilotSettings']['maxThroughput'] = max_throughput
771770
if increment_percent:
772771
new_throughput_properties['content']['offerAutopilotSettings']['autoUpgradePolicy']['throughputPolicy']['incrementPercent'] = increment_percent # pylint: disable=line-too-long
773772
if throughput.offer_throughput:

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

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ async def read(
156156
:returns: Dict representing the retrieved container.
157157
:rtype: Dict[str, Any]
158158
"""
159-
response_hook = kwargs.pop('response_hook', None)
160159
if session_token is not None:
161160
kwargs['session_token'] = session_token
162161
if priority_level is not None:
@@ -173,8 +172,6 @@ async def read(
173172
self._properties = await self.client_connection.ReadContainer(
174173
collection_link, options=request_options, **kwargs
175174
)
176-
if response_hook:
177-
response_hook(self.client_connection.last_response_headers, self._properties)
178175
return self._properties
179176

180177
@distributed_trace_async
@@ -220,7 +217,6 @@ async def create_item(
220217
:returns: A dict representing the new item.
221218
:rtype: Dict[str, Any]
222219
"""
223-
response_hook = kwargs.pop('response_hook', None)
224220
if pre_trigger_include is not None:
225221
kwargs['pre_trigger_include'] = pre_trigger_include
226222
if post_trigger_include is not None:
@@ -243,8 +239,6 @@ async def create_item(
243239
result = await self.client_connection.CreateItem(
244240
database_or_container_link=self.container_link, document=body, options=request_options, **kwargs
245241
)
246-
if response_hook:
247-
response_hook(self.client_connection.last_response_headers, result)
248242
return result
249243

250244
@distributed_trace_async
@@ -291,7 +285,6 @@ async def read_item(
291285
:caption: Get an item from the database and update one of its properties:
292286
:name: update_item
293287
"""
294-
response_hook = kwargs.pop('response_hook', None)
295288
doc_link = self._get_document_link(item)
296289
if post_trigger_include is not None:
297290
kwargs['post_trigger_include'] = post_trigger_include
@@ -309,10 +302,7 @@ async def read_item(
309302
validate_cache_staleness_value(max_integrated_cache_staleness_in_ms)
310303
request_options["maxIntegratedCacheStaleness"] = max_integrated_cache_staleness_in_ms
311304

312-
result = await self.client_connection.ReadItem(document_link=doc_link, options=request_options, **kwargs)
313-
if response_hook:
314-
response_hook(self.client_connection.last_response_headers, result)
315-
return result
305+
return await self.client_connection.ReadItem(document_link=doc_link, options=request_options, **kwargs)
316306

317307
@distributed_trace
318308
def read_all_items(
@@ -571,7 +561,6 @@ async def upsert_item(
571561
:returns: A dict representing the upserted item.
572562
:rtype: Dict[str, Any]
573563
"""
574-
response_hook = kwargs.pop('response_hook', None)
575564
if pre_trigger_include is not None:
576565
kwargs['pre_trigger_include'] = pre_trigger_include
577566
if post_trigger_include is not None:
@@ -595,8 +584,6 @@ async def upsert_item(
595584
options=request_options,
596585
**kwargs
597586
)
598-
if response_hook:
599-
response_hook(self.client_connection.last_response_headers, result)
600587
return result
601588

602589
@distributed_trace_async
@@ -639,7 +626,6 @@ async def replace_item(
639626
:returns: A dict representing the item after replace went through.
640627
:rtype: Dict[str, Any]
641628
"""
642-
response_hook = kwargs.pop('response_hook', None)
643629
item_link = self._get_document_link(item)
644630
if pre_trigger_include is not None:
645631
kwargs['pre_trigger_include'] = pre_trigger_include
@@ -661,8 +647,6 @@ async def replace_item(
661647
result = await self.client_connection.ReplaceItem(
662648
document_link=item_link, new_document=body, options=request_options, **kwargs
663649
)
664-
if response_hook:
665-
response_hook(self.client_connection.last_response_headers, result)
666650
return result
667651

668652
@distributed_trace_async
@@ -708,7 +692,6 @@ async def patch_item(
708692
given id does not exist.
709693
:rtype: dict[str, Any]
710694
"""
711-
response_hook = kwargs.pop('response_hook', None)
712695
if pre_trigger_include is not None:
713696
kwargs['pre_trigger_include'] = pre_trigger_include
714697
if post_trigger_include is not None:
@@ -728,11 +711,8 @@ async def patch_item(
728711
request_options["filterPredicate"] = filter_predicate
729712

730713
item_link = self._get_document_link(item)
731-
result = await self.client_connection.PatchItem(
714+
return await self.client_connection.PatchItem(
732715
document_link=item_link, operations=patch_operations, options=request_options, **kwargs)
733-
if response_hook:
734-
response_hook(self.client_connection.last_response_headers, result)
735-
return result
736716

737717
@distributed_trace_async
738718
async def delete_item(
@@ -770,7 +750,6 @@ async def delete_item(
770750
:raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The item does not exist in the container.
771751
:rtype: None
772752
"""
773-
response_hook = kwargs.pop('response_hook', None)
774753
if pre_trigger_include is not None:
775754
kwargs['pre_trigger_include'] = pre_trigger_include
776755
if post_trigger_include is not None:
@@ -788,8 +767,6 @@ async def delete_item(
788767

789768
document_link = self._get_document_link(item)
790769
await self.client_connection.DeleteItem(document_link=document_link, options=request_options, **kwargs)
791-
if response_hook:
792-
response_hook(self.client_connection.last_response_headers, None)
793770

794771
@distributed_trace_async
795772
async def get_throughput(self, **kwargs: Any) -> ThroughputProperties:
@@ -842,7 +819,6 @@ async def replace_throughput(
842819
:returns: ThroughputProperties for the container, updated with new throughput.
843820
:rtype: ~azure.cosmos.offer.ThroughputProperties
844821
"""
845-
response_hook = kwargs.pop('response_hook', None)
846822
properties = await self._get_properties()
847823
link = properties["_self"]
848824
query_spec = {
@@ -860,8 +836,6 @@ async def replace_throughput(
860836
_replace_throughput(throughput=throughput, new_throughput_properties=new_offer)
861837
data = await self.client_connection.ReplaceOffer(offer_link=throughput_properties[0]["_self"],
862838
offer=throughput_properties[0], **kwargs)
863-
if response_hook:
864-
response_hook(self.client_connection.last_response_headers, data)
865839

866840
return ThroughputProperties(offer_throughput=data["content"]["offerThroughput"], properties=data)
867841

@@ -955,13 +929,10 @@ async def get_conflict(
955929
:rtype: Dict[str, Any]
956930
"""
957931
request_options = _build_options(kwargs)
958-
response_hook = kwargs.pop('response_hook', None)
959932
request_options["partitionKey"] = await self._set_partition_key(partition_key)
960933
result = await self.client_connection.ReadConflict(
961934
conflict_link=self._get_conflict_link(conflict), options=request_options, **kwargs
962935
)
963-
if response_hook:
964-
response_hook(self.client_connection.last_response_headers, result)
965936
return result
966937

967938
@distributed_trace_async
@@ -986,13 +957,11 @@ async def delete_conflict(
986957
:rtype: None
987958
"""
988959
request_options = _build_options(kwargs)
989-
response_hook = kwargs.pop('response_hook', None)
990960
request_options["partitionKey"] = await self._set_partition_key(partition_key)
961+
991962
await self.client_connection.DeleteConflict(
992963
conflict_link=self._get_conflict_link(conflict), options=request_options, **kwargs
993964
)
994-
if response_hook:
995-
response_hook(self.client_connection.last_response_headers, None)
996965

997966
@distributed_trace_async
998967
async def delete_all_items_by_partition_key(
@@ -1023,7 +992,6 @@ async def delete_all_items_by_partition_key(
1023992
:keyword Callable response_hook: A callable invoked with the response metadata.
1024993
:rtype: None
1025994
"""
1026-
response_hook = kwargs.pop('response_hook', None)
1027995
if pre_trigger_include is not None:
1028996
kwargs['pre_trigger_include'] = pre_trigger_include
1029997
if post_trigger_include is not None:
@@ -1040,8 +1008,6 @@ async def delete_all_items_by_partition_key(
10401008

10411009
await self.client_connection.DeleteAllItemsByPartitionKey(collection_link=self.container_link,
10421010
options=request_options, **kwargs)
1043-
if response_hook:
1044-
response_hook(self.client_connection.last_response_headers, None)
10451011

10461012
@distributed_trace_async
10471013
async def execute_item_batch(
@@ -1074,7 +1040,6 @@ async def execute_item_batch(
10741040
:raises ~azure.cosmos.exceptions.CosmosBatchOperationError: A transactional batch operation failed in the batch.
10751041
:rtype: List[Dict[str, Any]]
10761042
"""
1077-
response_hook = kwargs.pop('response_hook', None)
10781043
if pre_trigger_include is not None:
10791044
kwargs['pre_trigger_include'] = pre_trigger_include
10801045
if post_trigger_include is not None:
@@ -1089,8 +1054,5 @@ async def execute_item_batch(
10891054
request_options["partitionKey"] = await self._set_partition_key(partition_key)
10901055
request_options["disableAutomaticIdGeneration"] = True
10911056

1092-
result = await self.client_connection.Batch(
1057+
return await self.client_connection.Batch(
10931058
collection_link=self.container_link, batch_operations=batch_operations, options=request_options, **kwargs)
1094-
if response_hook:
1095-
response_hook(self.client_connection.last_response_headers, result)
1096-
return result

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ async def create_database(
271271
:caption: Create a database in the Cosmos DB account:
272272
:name: create_database
273273
"""
274-
response_hook = kwargs.pop('response_hook', None)
275274
if session_token is not None:
276275
kwargs["session_token"] = session_token
277276
if initial_headers is not None:
@@ -284,8 +283,6 @@ async def create_database(
284283
_set_throughput_options(offer=offer_throughput, request_options=request_options)
285284

286285
result = await self.client_connection.CreateDatabase(database=dict(id=id), options=request_options, **kwargs)
287-
if response_hook:
288-
response_hook(self.client_connection.last_response_headers, result)
289286
return DatabaseProxy(self.client_connection, id=result["id"], properties=result)
290287

291288
@distributed_trace_async

0 commit comments

Comments
 (0)