Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
309c385
Initial draft
FabianMeiswinkel Sep 12, 2024
cc72dc3
Adding tests
FabianMeiswinkel Sep 13, 2024
a201167
Renaming parameter
FabianMeiswinkel Sep 19, 2024
d85a2b5
Update container.py
FabianMeiswinkel Sep 19, 2024
79a9bb6
Renaming test file
FabianMeiswinkel Sep 19, 2024
f9bfaa0
Fixing LINT issues
FabianMeiswinkel Sep 19, 2024
0c15374
Update container.py
FabianMeiswinkel Sep 19, 2024
ed27e02
Update _base.py
FabianMeiswinkel Sep 19, 2024
38fd806
Update _base.py
FabianMeiswinkel Sep 19, 2024
6edd050
Fixing tests
FabianMeiswinkel Sep 19, 2024
ffecd7f
Fixing tests
FabianMeiswinkel Sep 19, 2024
4920e8d
Adding support to disable response payload on write for AIO
FabianMeiswinkel Sep 20, 2024
8b08b1a
Update CHANGELOG.md
FabianMeiswinkel Sep 20, 2024
c57117e
Update _cosmos_client.py
FabianMeiswinkel Sep 20, 2024
3cb08a4
Reacting to code review comments
FabianMeiswinkel Sep 20, 2024
22531ff
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
FabianMeiswinkel Sep 20, 2024
5a8192c
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
FabianMeiswinkel Sep 20, 2024
6abefa8
Addressing code review feedback
FabianMeiswinkel Sep 30, 2024
f0d8185
Addressed CR feedback
FabianMeiswinkel Oct 1, 2024
03b4915
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
FabianMeiswinkel Oct 1, 2024
e176d2f
Fixing pyLint errors
FabianMeiswinkel Oct 1, 2024
407f151
Fixing pylint errors
FabianMeiswinkel Oct 1, 2024
45ebbd0
Update test_crud.py
FabianMeiswinkel Oct 1, 2024
93e33d6
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
FabianMeiswinkel Oct 2, 2024
4843c2d
Fixing svc regression
FabianMeiswinkel Oct 2, 2024
cd91240
Update sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py
FabianMeiswinkel Oct 2, 2024
d104ac3
Reacting to code review feedback.
FabianMeiswinkel Oct 2, 2024
4118a31
Merge branch 'users/fabianm/hotfix20240910' of https://github.com/Fab…
FabianMeiswinkel Oct 2, 2024
54921e8
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
FabianMeiswinkel Oct 2, 2024
88a229a
Update container.py
FabianMeiswinkel Oct 2, 2024
8a28095
Update test_query_vector_similarity.py
FabianMeiswinkel Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Features Added
* Added Retry Policy for Container Recreate in the Python SDK. See [PR 36043](https://github.com/Azure/azure-sdk-for-python/pull/36043)
* Added option to disable write payload on writes. See [PR 37365](https://github.com/Azure/azure-sdk-for-python/pull/37365)

#### Breaking Changes

Expand Down
12 changes: 11 additions & 1 deletion sdk/cosmos/azure-cosmos/azure/cosmos/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
'is_query_plan_request': 'isQueryPlanRequest',
'supported_query_features': 'supportedQueryFeatures',
'query_version': 'queryVersion',
'priority': 'priorityLevel'
'priority': 'priorityLevel',
'response_payload_on_write_disabled': 'responsePayloadOnWriteDisabled'
}

# Cosmos resource ID validation regex breakdown:
Expand Down Expand Up @@ -318,6 +319,15 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
if options.get("correlatedActivityId"):
headers[http_constants.HttpHeaders.CorrelatedActivityId] = options["correlatedActivityId"]

if resource_type == "docs" and verb != "get":
if "responsePayloadOnWriteDisabled" in options:
responsePayloadOnWriteDisabled = options["responsePayloadOnWriteDisabled"]
else:
responsePayloadOnWriteDisabled = cosmos_client_connection.connection_policy.ResponsePayloadOnWriteDisabled

if responsePayloadOnWriteDisabled:
headers[http_constants.HttpHeaders.Prefer] = http_constants.HttpHeaderValues.PreferReturnMinimal

# If it is an operation at the container level, verify the rid of the container to see if the cache needs to be
# refreshed.
if resource_type != 'dbs' and options.get("containerRID"):
Expand Down
52 changes: 40 additions & 12 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ async def create_item(
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Create an item in the container.

To update or replace an existing item, use the
Expand All @@ -216,8 +217,12 @@ async def create_item(
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Item with the given ID already exists.
:returns: A dict representing the new item.
:rtype: Dict[str, Any]
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip
sending response payloads. When not specified explicitly here, the default value will be determined from
kwargs or when also not specified there from client-level kwargs.
:returns: A dict representing the item after replace went through or if response payload on write is disabled
None.
:rtype: Optional[Dict[str, Any]]
"""
if pre_trigger_include is not None:
kwargs['pre_trigger_include'] = pre_trigger_include
Expand All @@ -233,6 +238,8 @@ async def create_item(
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = _build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = not enable_automatic_id_generation
if indexing_directive is not None:
Expand Down Expand Up @@ -552,8 +559,9 @@ async def upsert_item(
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Insert or update the specified item.

If the item already exists in the container, it is replaced. If the item
Expand All @@ -574,8 +582,12 @@ async def upsert_item(
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item could not be upserted.
:returns: A dict representing the upserted item.
:rtype: Dict[str, Any]
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip
sending response payloads. When not specified explicitly here, the default value will be determined from
kwargs or when also not specified there from client-level kwargs.
:returns: A dict representing the item after replace went through or if response payload on write is disabled
None.
:rtype: Optional[Dict[str, Any]]
"""
if pre_trigger_include is not None:
kwargs['pre_trigger_include'] = pre_trigger_include
Expand All @@ -591,6 +603,8 @@ async def upsert_item(
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = _build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = True
if self.container_link in self.__get_client_container_caches():
Expand All @@ -617,8 +631,9 @@ async def replace_item(
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Replaces the specified item if it exists in the container.

If the item does not already exist in the container, an exception is raised.
Expand All @@ -641,8 +656,12 @@ async def replace_item(
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The replace failed or the item with
given id does not exist.
:returns: A dict representing the item after replace went through.
:rtype: Dict[str, Any]
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip
sending response payloads. When not specified explicitly here, the default value will be determined from
kwargs or when also not specified there from client-level kwargs.
:returns: A dict representing the item after replace went through or if response payload on write is disabled
None.
:rtype: Optional[Dict[str, Any]]
"""
item_link = self._get_document_link(item)
if pre_trigger_include is not None:
Expand All @@ -659,6 +678,8 @@ async def replace_item(
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = _build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = True
if self.container_link in self.__get_client_container_caches():
Expand All @@ -683,8 +704,9 @@ async def patch_item(
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
""" Patches the specified item with the provided operations if it
exists in the container.

Expand All @@ -707,10 +729,14 @@ async def patch_item(
:keyword Literal["High", "Low"] priority: Priority based execution allows users to set a priority for each
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:returns: A dict representing the item after the patch operations went through.
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip
sending response payloads. When not specified explicitly here, the default value will be determined from
kwargs or when also not specified there from client-level kwargs.
:returns: A dict representing the item after replace went through or if response payload on write is disabled
None.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The patch operations failed or the item with
given id does not exist.
:rtype: dict[str, Any]
:rtype: Optional[dict[str, Any]]
"""
if pre_trigger_include is not None:
kwargs['pre_trigger_include'] = pre_trigger_include
Expand All @@ -724,6 +750,8 @@ async def patch_item(
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = _build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = True
request_options["partitionKey"] = await self._set_partition_key(partition_key)
Expand Down
3 changes: 3 additions & 0 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _build_connection_policy(kwargs: Dict[str, Any]) -> ConnectionPolicy:
retry_backoff_factor=kwargs.pop('retry_backoff_factor', 0.8),
)
policy.ConnectionRetryConfiguration = connection_retry
policy.ResponsePayloadOnWriteDisabled = kwargs.pop('response_payload_on_write_disabled', False)
return policy


Expand Down Expand Up @@ -156,6 +157,8 @@ class CosmosClient: # pylint: disable=client-accepts-api-version-keyword
Must be used along with a logger to work.
:keyword ~logging.Logger logger: Logger to be used for collecting request diagnostics. Can be passed in at client
level (to log all requests) or at a single request level. Requests will be logged at INFO level.
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip sending
response payloads.

.. admonition:: Example:

Expand Down
50 changes: 38 additions & 12 deletions sdk/cosmos/azure-cosmos/azure/cosmos/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,9 @@ def replace_item( # pylint:disable=docstring-missing-param
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Replaces the specified item if it exists in the container.

If the item does not already exist in the container, an exception is raised.
Expand All @@ -540,10 +541,14 @@ def replace_item( # pylint:disable=docstring-missing-param
:keyword Literal["High", "Low"] priority: Priority based execution allows users to set a priority for each
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:returns: A dict representing the item after replace went through.
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip
sending response payloads. When not specified explicitly here, the default value will be determined from
kwargs or when also not specified there from client-level kwargs.
:returns: A dict representing the item after replace went through or if response payload on write is disabled
None.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The replace operation failed or the item with
given id does not exist.
:rtype: Dict[str, Any]
:rtype: Optional[Dict[str, Any]]
"""
item_link = self._get_document_link(item)
if pre_trigger_include is not None:
Expand All @@ -560,6 +565,8 @@ def replace_item( # pylint:disable=docstring-missing-param
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = True
if populate_query_metrics is not None:
Expand Down Expand Up @@ -589,8 +596,9 @@ def upsert_item( # pylint:disable=docstring-missing-param
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Insert or update the specified item.

If the item already exists in the container, it is replaced. If the item
Expand All @@ -609,9 +617,12 @@ def upsert_item( # pylint:disable=docstring-missing-param
:keyword Literal["High", "Low"] priority: Priority based execution allows users to set a priority for each
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:returns: A dict representing the upserted item.
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip sending
response payloads. When not specified explicitly here, the default value will be determined from kwargs or
when also not specified there from client-level kwargs.
:returns: A dict representing the upserted item or if response payload on write is disabled None.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The given item could not be upserted.
:rtype: Dict[str, Any]
:rtype: Optional[Dict[str, Any]]
"""
if pre_trigger_include is not None:
kwargs['pre_trigger_include'] = pre_trigger_include
Expand All @@ -627,6 +638,8 @@ def upsert_item( # pylint:disable=docstring-missing-param
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = True
if populate_query_metrics is not None:
Expand Down Expand Up @@ -660,8 +673,9 @@ def create_item( # pylint:disable=docstring-missing-param
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
"""Create an item in the container.

To update or replace an existing item, use the
Expand All @@ -684,9 +698,12 @@ def create_item( # pylint:disable=docstring-missing-param
:keyword Literal["High", "Low"] priority: Priority based execution allows users to set a priority for each
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:returns: A dict representing the new item.
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip sending
response payloads. When not specified explicitly here, the default value will be determined from kwargs or
when also not specified there from client-level kwargs.
:returns: A dict representing the new item or if response payload on write is disabled None.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Item with the given ID already exists.
:rtype: Dict[str, Any]
:rtype: Optional[Dict[str, Any]]
"""
if pre_trigger_include is not None:
kwargs['pre_trigger_include'] = pre_trigger_include
Expand All @@ -702,6 +719,8 @@ def create_item( # pylint:disable=docstring-missing-param
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = not enable_automatic_id_generation
if populate_query_metrics:
Expand Down Expand Up @@ -731,8 +750,9 @@ def patch_item(
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
priority: Optional[Literal["High", "Low"]] = None,
response_payload_on_write_disabled: Optional[bool] = None,
**kwargs: Any
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
""" Patches the specified item with the provided operations if it
exists in the container.

Expand All @@ -755,10 +775,14 @@ def patch_item(
:keyword Literal["High", "Low"] priority: Priority based execution allows users to set a priority for each
request. Once the user has reached their provisioned throughput, low priority requests are throttled
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:returns: A dict representing the item after the patch operations went through.
:keyword bool response_payload_on_write_disabled: Indicates whether service should be instructed to skip sending
response payloads. When not specified explicitly here, the default value will be determined from kwargs or
when also not specified there from client-level kwargs.
:returns: A dict representing the item after the patch operations went through or if response payload on write
is disabled None.
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The patch operations failed or the item with
given id does not exist.
:rtype: dict[str, Any]
:rtype: Optional[Dict[str, Any]]
"""
if pre_trigger_include is not None:
kwargs['pre_trigger_include'] = pre_trigger_include
Expand All @@ -772,6 +796,8 @@ def patch_item(
kwargs['etag'] = etag
if match_condition is not None:
kwargs['match_condition'] = match_condition
if response_payload_on_write_disabled is not None:
kwargs['response_payload_on_write_disabled'] = response_payload_on_write_disabled
request_options = build_options(kwargs)
request_options["disableAutomaticIdGeneration"] = True
request_options["partitionKey"] = self._set_partition_key(partition_key)
Expand Down
Loading