From 5315415d39d8df394eea81fbf79e764f435668a6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:08:35 +0000 Subject: [PATCH 1/5] Update Python guidelines for conditional requests with exception details Agent-Logs-Url: https://github.com/Azure/azure-sdk/sessions/26ee6d2d-6e89-43db-bff9-07b9cdc2e3dc Co-authored-by: johanste <15110018+johanste@users.noreply.github.com> --- docs/python/design.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/python/design.md b/docs/python/design.md index 8c0e8eea2868..9530e1531a15 100644 --- a/docs/python/design.md +++ b/docs/python/design.md @@ -431,6 +431,10 @@ In cases where a service API is not explicitly implemented as a long-running ope {% include requirement/MUST id="python-method-conditional-request-etag" %} add a keyword-only `etag` parameter for service methods that support conditional requests. For service methods that take a model instance that has an `etag` property, the explicit `etag` value passed in overrides the value in the model instance. +{% include requirement/MUST id="python-method-conditional-request-raise-resource-modified" %} raise `azure.core.exceptions.ResourceModifiedError` when an unsafe conditional request (e.g. `PUT`, `POST`, `DELETE`) fails because the condition was not met. This typically corresponds to an HTTP `412 Precondition Failed` or `409 Conflict` response. + +{% include requirement/MUST id="python-method-conditional-request-raise-resource-not-modified" %} raise `azure.core.exceptions.ResourceNotModifiedError` when a safe conditional request (e.g. `GET`, `HEAD`) determines the resource has not changed. This corresponds to an HTTP `304 Not Modified` response. + ```python class Thing: From 5089033d8ee72a3a32321788776ebdf9469fd625 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:12:09 +0000 Subject: [PATCH 2/5] Remove 409 Conflict from ResourceModifiedError guideline Agent-Logs-Url: https://github.com/Azure/azure-sdk/sessions/f5b3b6f9-095c-48ba-8f90-d3e07796c24c Co-authored-by: johanste <15110018+johanste@users.noreply.github.com> --- docs/python/design.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/design.md b/docs/python/design.md index 9530e1531a15..4fbce52d6f27 100644 --- a/docs/python/design.md +++ b/docs/python/design.md @@ -431,7 +431,7 @@ In cases where a service API is not explicitly implemented as a long-running ope {% include requirement/MUST id="python-method-conditional-request-etag" %} add a keyword-only `etag` parameter for service methods that support conditional requests. For service methods that take a model instance that has an `etag` property, the explicit `etag` value passed in overrides the value in the model instance. -{% include requirement/MUST id="python-method-conditional-request-raise-resource-modified" %} raise `azure.core.exceptions.ResourceModifiedError` when an unsafe conditional request (e.g. `PUT`, `POST`, `DELETE`) fails because the condition was not met. This typically corresponds to an HTTP `412 Precondition Failed` or `409 Conflict` response. +{% include requirement/MUST id="python-method-conditional-request-raise-resource-modified" %} raise `azure.core.exceptions.ResourceModifiedError` when an unsafe conditional request (e.g. `PUT`, `POST`, `DELETE`) fails because the condition was not met. This typically corresponds to an HTTP `412 Precondition Failed` response. {% include requirement/MUST id="python-method-conditional-request-raise-resource-not-modified" %} raise `azure.core.exceptions.ResourceNotModifiedError` when a safe conditional request (e.g. `GET`, `HEAD`) determines the resource has not changed. This corresponds to an HTTP `304 Not Modified` response. From 9e4abc2b612f59542b3449c60b68570e2688bdaa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:20:30 +0000 Subject: [PATCH 3/5] Add implementation note for conditional request error mapping using map_error Agent-Logs-Url: https://github.com/Azure/azure-sdk/sessions/170c571c-1fff-4fc2-9337-6749d8e16c19 Co-authored-by: johanste <15110018+johanste@users.noreply.github.com> --- docs/python/design.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/python/design.md b/docs/python/design.md index 4fbce52d6f27..755222090d69 100644 --- a/docs/python/design.md +++ b/docs/python/design.md @@ -435,6 +435,21 @@ In cases where a service API is not explicitly implemented as a long-running ope {% include requirement/MUST id="python-method-conditional-request-raise-resource-not-modified" %} raise `azure.core.exceptions.ResourceNotModifiedError` when a safe conditional request (e.g. `GET`, `HEAD`) determines the resource has not changed. This corresponds to an HTTP `304 Not Modified` response. +> Note: Use the `map_error` function from `azure.core.exceptions` to map HTTP status codes to the appropriate exception types in your service method implementation: + +```python +from azure.core.exceptions import HttpResponseError, ResourceModifiedError, ResourceNotModifiedError, map_error + +error_map = { + 304: ResourceNotModifiedError, + 412: ResourceModifiedError, +} + +if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) +``` + ```python class Thing: From 4a85602a0fe1edf9f8e85c7be0818827d9f49e35 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:04:48 +0000 Subject: [PATCH 4/5] docs(python): Update conditional request implementation note for DPG Agent-Logs-Url: https://github.com/Azure/azure-sdk/sessions/7eff84c7-a308-46ce-b451-6659186c69e0 Co-authored-by: johanste <15110018+johanste@users.noreply.github.com> --- docs/python/design.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/design.md b/docs/python/design.md index 755222090d69..859ffff12eb6 100644 --- a/docs/python/design.md +++ b/docs/python/design.md @@ -435,7 +435,7 @@ In cases where a service API is not explicitly implemented as a long-running ope {% include requirement/MUST id="python-method-conditional-request-raise-resource-not-modified" %} raise `azure.core.exceptions.ResourceNotModifiedError` when a safe conditional request (e.g. `GET`, `HEAD`) determines the resource has not changed. This corresponds to an HTTP `304 Not Modified` response. -> Note: Use the `map_error` function from `azure.core.exceptions` to map HTTP status codes to the appropriate exception types in your service method implementation: +> Note: Use the `map_error` function from `azure.core.exceptions` to map HTTP status codes to the appropriate exception types in your service method implementation. DPG-generated code already includes `304 → ResourceNotModifiedError` by default. For unsafe conditional requests, you must also add `412 → ResourceModifiedError` to the error map (either by declaring it as an error response in TypeSpec, or by updating the generated code manually): ```python from azure.core.exceptions import HttpResponseError, ResourceModifiedError, ResourceNotModifiedError, map_error From 408baacc1ac9a5cc26b4c07c9f9c136d6b41c8cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:12:39 +0000 Subject: [PATCH 5/5] docs(python): Nuance 412 error mapping in conditional request implementation note Agent-Logs-Url: https://github.com/Azure/azure-sdk/sessions/dcd48ca4-ecff-4dce-bacb-a7a0863410c7 Co-authored-by: johanste <15110018+johanste@users.noreply.github.com> --- docs/python/design.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/python/design.md b/docs/python/design.md index 859ffff12eb6..3cc559433e49 100644 --- a/docs/python/design.md +++ b/docs/python/design.md @@ -435,15 +435,27 @@ In cases where a service API is not explicitly implemented as a long-running ope {% include requirement/MUST id="python-method-conditional-request-raise-resource-not-modified" %} raise `azure.core.exceptions.ResourceNotModifiedError` when a safe conditional request (e.g. `GET`, `HEAD`) determines the resource has not changed. This corresponds to an HTTP `304 Not Modified` response. -> Note: Use the `map_error` function from `azure.core.exceptions` to map HTTP status codes to the appropriate exception types in your service method implementation. DPG-generated code already includes `304 → ResourceNotModifiedError` by default. For unsafe conditional requests, you must also add `412 → ResourceModifiedError` to the error map (either by declaring it as an error response in TypeSpec, or by updating the generated code manually): +> Note: Use the `map_error` function from `azure.core.exceptions` to map HTTP status codes to the appropriate exception types in your service method implementation. DPG-generated code already includes `304 → ResourceNotModifiedError` by default. For unsafe conditional requests, you must also handle `412 Precondition Failed`. Because HTTP 412 only indicates that one or more preconditions failed, the correct exception type depends on which condition was passed by the caller — it is not always `ResourceModifiedError`: ```python -from azure.core.exceptions import HttpResponseError, ResourceModifiedError, ResourceNotModifiedError, map_error +from azure.core.exceptions import ( + HttpResponseError, ResourceExistsError, ResourceModifiedError, + ResourceNotFoundError, ResourceNotModifiedError, map_error +) +from azure.core import MatchConditions error_map = { 304: ResourceNotModifiedError, - 412: ResourceModifiedError, } +if match_condition == MatchConditions.IfNotModified: + # Condition: If-Match / If-Unmodified-Since — resource was modified + error_map[412] = ResourceModifiedError +elif match_condition == MatchConditions.IfPresent: + # Condition: If-Match: * — resource does not exist + error_map[412] = ResourceNotFoundError +elif match_condition == MatchConditions.IfMissing: + # Condition: If-None-Match: * — resource already exists + error_map[412] = ResourceExistsError if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map)