Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions packages/autorest.python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release

## 6.27.0

### Features

- [#2959](https://github.com/Azure/autorest.python/pull/2959) Refine exception handling logic and support exception with ranged status code


## 6.26.7

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions packages/autorest.python/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autorest/python",
"version": "6.26.7",
"version": "6.27.0",
"description": "The Python extension for generators in AutoRest.",
"scripts": {
"start": "node ./scripts/run-python3.js ./scripts/start.py",
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "~0.3.12",
"@typespec/http-client-python": "~0.4.2",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "~4.19.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar, cast
from typing import Any, Callable, Dict, Optional, TypeVar

from azure.core.exceptions import (
ClientAuthenticationError,
Expand Down Expand Up @@ -68,14 +68,6 @@ async def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[_models.Pe
401: ClientAuthenticationError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
400: HttpResponseError,
404: cast(
Type[HttpResponseError],
lambda response: ResourceNotFoundError(
response=response, model=self._deserialize(_models.NotFoundErrorBase, response)
),
),
501: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -99,8 +91,12 @@ async def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[_models.Pe
response = pipeline_response.http_response

if response.status_code not in [200, 202]:
map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore
raise HttpResponseError(response=response)
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = None
if response.status_code == 404:
error = self._deserialize.failsafe_deserialize(_models.NotFoundErrorBase, pipeline_response)
raise ResourceNotFoundError(response=response, model=error)
raise HttpResponseError(response=response, model=error)

deserialized = None
if response.status_code == 200:
Expand All @@ -126,12 +122,6 @@ async def do_something(self, what_action: str, **kwargs: Any) -> _models.PetActi
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: cast(
Type[HttpResponseError],
lambda response: HttpResponseError(
response=response, model=self._deserialize(_models.PetActionError, response)
),
),
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -156,7 +146,11 @@ async def do_something(self, what_action: str, **kwargs: Any) -> _models.PetActi

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
error = None
if response.status_code == 500:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
else:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = self._deserialize("PetAction", pipeline_response.http_response)
Expand All @@ -183,12 +177,6 @@ async def has_models_param(self, models: str = "value1", **kwargs: Any) -> None:
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: cast(
Type[HttpResponseError],
lambda response: HttpResponseError(
response=response, model=self._deserialize(_models.PetActionError, response)
),
),
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -213,7 +201,11 @@ async def has_models_param(self, models: str = "value1", **kwargs: Any) -> None:

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
error = None
if response.status_code == 500:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
else:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
raise HttpResponseError(response=response, model=error)

if cls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar, cast
from typing import Any, Callable, Dict, Optional, TypeVar

from azure.core.exceptions import (
ClientAuthenticationError,
Expand Down Expand Up @@ -125,14 +125,6 @@ def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[_models.Pet]:
401: ClientAuthenticationError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
400: HttpResponseError,
404: cast(
Type[HttpResponseError],
lambda response: ResourceNotFoundError(
response=response, model=self._deserialize(_models.NotFoundErrorBase, response)
),
),
501: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -156,8 +148,12 @@ def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[_models.Pet]:
response = pipeline_response.http_response

if response.status_code not in [200, 202]:
map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore
raise HttpResponseError(response=response)
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = None
if response.status_code == 404:
error = self._deserialize.failsafe_deserialize(_models.NotFoundErrorBase, pipeline_response)
raise ResourceNotFoundError(response=response, model=error)
raise HttpResponseError(response=response, model=error)

deserialized = None
if response.status_code == 200:
Expand All @@ -183,12 +179,6 @@ def do_something(self, what_action: str, **kwargs: Any) -> _models.PetAction:
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: cast(
Type[HttpResponseError],
lambda response: HttpResponseError(
response=response, model=self._deserialize(_models.PetActionError, response)
),
),
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -213,7 +203,11 @@ def do_something(self, what_action: str, **kwargs: Any) -> _models.PetAction:

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
error = None
if response.status_code == 500:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
else:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = self._deserialize("PetAction", pipeline_response.http_response)
Expand Down Expand Up @@ -242,12 +236,6 @@ def has_models_param( # pylint: disable=inconsistent-return-statements
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: cast(
Type[HttpResponseError],
lambda response: HttpResponseError(
response=response, model=self._deserialize(_models.PetActionError, response)
),
),
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -272,7 +260,11 @@ def has_models_param( # pylint: disable=inconsistent-return-statements

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
error = None
if response.status_code == 500:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
else:
error = self._deserialize.failsafe_deserialize(_models.PetActionError, pipeline_response)
raise HttpResponseError(response=response, model=error)

if cls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar, cast
from typing import Any, Callable, Dict, Optional, TypeVar, cast

from azure.core.exceptions import (
ClientAuthenticationError,
Expand Down Expand Up @@ -73,11 +73,9 @@ async def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[JSON]:
"""
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
400: HttpResponseError,
404: cast(Type[HttpResponseError], lambda response: ResourceNotFoundError(response=response)),
501: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -101,7 +99,7 @@ async def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[JSON]:
response = pipeline_response.http_response

if response.status_code not in [200, 202]:
map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

deserialized = None
Expand Down Expand Up @@ -139,7 +137,6 @@ async def do_something(self, what_action: str, **kwargs: Any) -> JSON:
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand Down Expand Up @@ -193,7 +190,6 @@ async def has_models_param(self, *, models: str = "value1", **kwargs: Any) -> No
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar, cast
from typing import Any, Callable, Dict, Optional, TypeVar, cast

from azure.core.exceptions import (
ClientAuthenticationError,
Expand Down Expand Up @@ -130,11 +130,9 @@ def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[JSON]:
"""
error_map: MutableMapping = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
400: HttpResponseError,
404: cast(Type[HttpResponseError], lambda response: ResourceNotFoundError(response=response)),
501: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand All @@ -158,7 +156,7 @@ def get_pet_by_id(self, pet_id: str, **kwargs: Any) -> Optional[JSON]:
response = pipeline_response.http_response

if response.status_code not in [200, 202]:
map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

deserialized = None
Expand Down Expand Up @@ -196,7 +194,6 @@ def do_something(self, what_action: str, **kwargs: Any) -> JSON:
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand Down Expand Up @@ -252,7 +249,6 @@ def has_models_param( # pylint: disable=inconsistent-return-statements
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
500: HttpResponseError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

Expand Down
12 changes: 12 additions & 0 deletions packages/typespec-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Release

## 0.37.0

### Bug Fixes

- [#2959](https://github.com/Azure/autorest.python/pull/2959) Filter out credential that python does not support for now
- [#2959](https://github.com/Azure/autorest.python/pull/2959) Ignore models only used as LRO envelope results because we don't do anything with them

### Features

- [#2959](https://github.com/Azure/autorest.python/pull/2959) Refine exception handling logic and support exception with ranged status code


## 0.36.7

### Bug Fixes
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-python",
"version": "0.36.7",
"version": "0.37.0",
"author": "Microsoft Corporation",
"description": "TypeSpec emitter for Python SDKs",
"homepage": "https://github.com/Azure/autorest.python",
Expand Down Expand Up @@ -54,13 +54,13 @@
"@azure-tools/typespec-azure-resource-manager": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.48.0 <3.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.48.0 <1.0.0"
"@azure-tools/typespec-client-generator-core": ">=0.48.5 <1.0.0"
},
"dependencies": {
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
"tsx": "~4.19.1",
"@typespec/http-client-python": "~0.3.12",
"@typespec/http-client-python": "~0.4.2",
"fs-extra": "~11.2.0"
},
"devDependencies": {
Expand All @@ -73,7 +73,7 @@
"@azure-tools/typespec-azure-core": "~0.48.0",
"@azure-tools/typespec-azure-rulesets": "~0.48.0",
"@azure-tools/typespec-autorest": "~0.48.0",
"@azure-tools/typespec-client-generator-core": "~0.48.0",
"@azure-tools/typespec-client-generator-core": "~0.48.5",
"@azure-tools/cadl-ranch-expect": "~0.15.6",
"@azure-tools/cadl-ranch-specs": "~0.39.1",
"@azure-tools/cadl-ranch": "~0.16.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,22 @@ def _deserialize(
return _deserialize_with_callable(deserializer, value)


def _failsafe_deserialize(
deserializer: typing.Any,
value: typing.Any,
module: typing.Optional[str] = None,
rf: typing.Optional["_RestField"] = None,
format: typing.Optional[str] = None,
) -> typing.Any:
try:
return _deserialize(deserializer, value, module, rf, format)
except DeserializationError:
_LOGGER.warning(
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
)
return None


class _RestField:
def __init__(
self,
Expand Down
Loading
Loading