Skip to content

Commit e2b5d31

Browse files
committed
_shared parity
1 parent fbb3841 commit e2b5d31

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/response_handlers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,8 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p
9292
)
9393
if not storage_error.response or storage_error.response.status_code in [200, 204]:
9494
raise storage_error
95-
# The generated layer now pre-maps 412 (Precondition Failed) responses to typed
96-
# exceptions based on the request's match condition (e.g. ResourceExistsError for
97-
# IfMissing, ResourceNotFoundError for IfPresent). Historically 412 was not
98-
# pre-mapped and always flowed through the error-code mapping below, surfacing as
99-
# ResourceModifiedError. Skip the "already serialized" shortcut for 412 so it is
100-
# re-mapped from x-ms-error-code (ConditionNotMet -> ResourceModifiedError) and the
101-
# public exception type is preserved for users.
102-
if storage_error.response.status_code != 412 and isinstance(
95+
# If it is one of those three then it has been serialized prior by the generated layer.
96+
if isinstance(
10397
storage_error,
10498
(PartialBatchErrorException, ClientAuthenticationError, ResourceNotFoundError, ResourceExistsError),
10599
):

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_deserialize.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ def deserialize_file_stream(
6565
) -> Tuple["LocationMode", Any]:
6666
file_properties = deserialize_file_properties(response, obj, headers)
6767
http_response = response.http_response
68-
# The TypeSpec-generated download returns a raw bytes iterator (from iter_bytes/iter_raw)
69-
# that doesn't allow attaching attributes. If properties can't be set on the stream
70-
# directly, wrap it so callers can still reach .properties and .response.
71-
try:
72-
obj.properties = file_properties
73-
except AttributeError:
68+
# The TypeSpec-generated download returns a raw bytes iterator or a structured-message
69+
# decoder rather than a response object that exposes .properties. When the stream can't
70+
# carry our metadata, wrap it so callers can still reach .properties and .response.
71+
if not hasattr(obj, "properties"):
7472
stream = _StreamWrapper(obj)
7573
stream.properties = file_properties
7674
stream.response = http_response
7775
return http_response.location_mode, stream
76+
obj.properties = file_properties
7877
return http_response.location_mode, obj
7978

8079

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/response_handlers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p
9393
)
9494
if not storage_error.response or storage_error.response.status_code in [200, 204]:
9595
raise storage_error
96-
# If it is one of those three then it has been serialized prior by the generated layer.
97-
if isinstance(
96+
# The generated layer now pre-maps 412 (Precondition Failed) responses to typed
97+
# exceptions based on the request's match condition (e.g. ResourceExistsError for
98+
# IfMissing, ResourceNotFoundError for IfPresent). Historically 412 was not
99+
# pre-mapped and always flowed through the error-code mapping below, surfacing as
100+
# ResourceModifiedError. Skip the "already serialized" shortcut for 412 so it is
101+
# re-mapped from x-ms-error-code (ConditionNotMet -> ResourceModifiedError) and the
102+
# public exception type is preserved for users.
103+
if storage_error.response.status_code != 412 and isinstance(
98104
storage_error,
99105
(PartialBatchErrorException, ClientAuthenticationError, ResourceNotFoundError, ResourceExistsError),
100106
):

0 commit comments

Comments
 (0)