Skip to content

Commit 4fd84e0

Browse files
authored
failsafe deserialize (#3163)
1 parent 3cc6c3f commit 4fd84e0

File tree

185 files changed

+894
-729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+894
-729
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: dependencies
3+
packages:
4+
- "@autorest/python"
5+
---
6+
7+
Bump dependency on `http-client-python`
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@azure-tools/typespec-python"
5+
---
6+
7+
Don't throw when deserializing error model responses

packages/autorest.python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "~0.15.0",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTE4NzMzOC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.15.0.tgz",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"

packages/typespec-python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"js-yaml": "~4.1.0",
6868
"semver": "~7.6.2",
6969
"tsx": "~4.19.1",
70-
"@typespec/http-client-python": "~0.15.0",
70+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTE4NzMzOC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.15.0.tgz",
7171
"fs-extra": "~11.2.0"
7272
},
7373
"devDependencies": {

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/_operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def invalid(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return
145145
map_error(status_code=response.status_code, response=response, error_map=error_map)
146146
error = None
147147
if response.status_code == 403:
148-
error = _failsafe_deserialize(_models.InvalidAuth, response.json())
148+
error = _failsafe_deserialize(_models.InvalidAuth, response)
149149
raise HttpResponseError(response=response, model=error)
150150

151151
if cls:

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/_utils/model_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from azure.core import CaseInsensitiveEnumMeta
3030
from azure.core.pipeline import PipelineResponse
3131
from azure.core.serialization import _Null
32+
from azure.core.rest import HttpResponse
3233

3334
_LOGGER = logging.getLogger(__name__)
3435

@@ -940,13 +941,13 @@ def _deserialize(
940941

941942
def _failsafe_deserialize(
942943
deserializer: typing.Any,
943-
value: typing.Any,
944+
response: HttpResponse,
944945
module: typing.Optional[str] = None,
945946
rf: typing.Optional["_RestField"] = None,
946947
format: typing.Optional[str] = None,
947948
) -> typing.Any:
948949
try:
949-
return _deserialize(deserializer, value, module, rf, format)
950+
return _deserialize(deserializer, response.json(), module, rf, format)
950951
except DeserializationError:
951952
_LOGGER.warning(
952953
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
@@ -956,10 +957,10 @@ def _failsafe_deserialize(
956957

957958
def _failsafe_deserialize_xml(
958959
deserializer: typing.Any,
959-
value: typing.Any,
960+
response: HttpResponse,
960961
) -> typing.Any:
961962
try:
962-
return _deserialize_xml(deserializer, value)
963+
return _deserialize_xml(deserializer, response.text())
963964
except DeserializationError:
964965
_LOGGER.warning(
965966
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/aio/_operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def invalid(self, **kwargs: Any) -> None:
121121
map_error(status_code=response.status_code, response=response, error_map=error_map)
122122
error = None
123123
if response.status_code == 403:
124-
error = _failsafe_deserialize(_models.InvalidAuth, response.json())
124+
error = _failsafe_deserialize(_models.InvalidAuth, response)
125125
raise HttpResponseError(response=response, model=error)
126126

127127
if cls:

packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def invalid(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return
145145
map_error(status_code=response.status_code, response=response, error_map=error_map)
146146
error = None
147147
if response.status_code == 403:
148-
error = _failsafe_deserialize(_models.InvalidAuth, response.json())
148+
error = _failsafe_deserialize(_models.InvalidAuth, response)
149149
raise HttpResponseError(response=response, model=error)
150150

151151
if cls:

packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_utils/model_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from azure.core import CaseInsensitiveEnumMeta
3030
from azure.core.pipeline import PipelineResponse
3131
from azure.core.serialization import _Null
32+
from azure.core.rest import HttpResponse
3233

3334
_LOGGER = logging.getLogger(__name__)
3435

@@ -940,13 +941,13 @@ def _deserialize(
940941

941942
def _failsafe_deserialize(
942943
deserializer: typing.Any,
943-
value: typing.Any,
944+
response: HttpResponse,
944945
module: typing.Optional[str] = None,
945946
rf: typing.Optional["_RestField"] = None,
946947
format: typing.Optional[str] = None,
947948
) -> typing.Any:
948949
try:
949-
return _deserialize(deserializer, value, module, rf, format)
950+
return _deserialize(deserializer, response.json(), module, rf, format)
950951
except DeserializationError:
951952
_LOGGER.warning(
952953
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
@@ -956,10 +957,10 @@ def _failsafe_deserialize(
956957

957958
def _failsafe_deserialize_xml(
958959
deserializer: typing.Any,
959-
value: typing.Any,
960+
response: HttpResponse,
960961
) -> typing.Any:
961962
try:
962-
return _deserialize_xml(deserializer, value)
963+
return _deserialize_xml(deserializer, response.text())
963964
except DeserializationError:
964965
_LOGGER.warning(
965966
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True

packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/aio/_operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def invalid(self, **kwargs: Any) -> None:
121121
map_error(status_code=response.status_code, response=response, error_map=error_map)
122122
error = None
123123
if response.status_code == 403:
124-
error = _failsafe_deserialize(_models.InvalidAuth, response.json())
124+
error = _failsafe_deserialize(_models.InvalidAuth, response)
125125
raise HttpResponseError(response=response, model=error)
126126

127127
if cls:

0 commit comments

Comments
 (0)