Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import-azure-core #247

Merged
merged 3 commits into from
May 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ To install:
Release History
---------------

2022-05-05 Version 0.7.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test for the serialization and deserialization errors to make sure we're throwing azure.core.exceptions.SerializationError and azure.core.exceptions.DeserializationError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I see there are many existing testcase around SerializationError/DeserializationError in test_serialization.py. So I added a test to make sure msrest.exceptions.SerializationError is the same one in azure.core.exceptions.
https://github.com/Azure/msrest-for-python/pull/247/files#diff-7f5a7271c4eef44b2f5fda6334ecae0952550de169520dde4a919d86949361c2R2585

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gdsuser1992 , latest msrest get worked with azure-core >=1.24.0.
Would you please make sure the azure-core at /tmp/8da4ea7dc4b7018/antenv/lib/python3.7/site-packages/azure/core/ does be 1.24.0 or 1.24.1?

+++++++++++++++++++++++++

**Features**

- Add `azure-core` as installation requirement #247
- Replace `SerializationError` and `DeserializationError` in `msrest.exceptions` with those in `azure.core` #247

2021-01-26 Version 0.6.21
+++++++++++++++++++++++++

Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pylint
aiohttp;python_full_version>="3.5.2"
# async in msrest was experimental, we won't update
trio==0.14.0;python_version == '3.5'
trio==0.16.0;python_version >= '3.6'
trio==0.16.0;python_version >= '3.6' and python_version < '3.10'
trio==0.20.0;python_version >= '3.10'
12 changes: 1 addition & 11 deletions msrest/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import sys

from typing import Callable, Any, Optional, TYPE_CHECKING

from azure.core.exceptions import SerializationError, DeserializationError

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,16 +68,6 @@ def __init__(self, message, inner_exception=None, *args, **kwargs):
super(ClientException, self).__init__(message, *args, **kwargs) # type: ignore


class SerializationError(ClientException):
"""Error raised during request serialization."""
pass


class DeserializationError(ClientException):
"""Error raised during response deserialization."""
pass


class TokenExpiredError(ClientException):
"""OAuth token expired, request failed."""
pass
Expand Down
14 changes: 11 additions & 3 deletions msrest/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
_serialized.update(_new_attr)
_new_attr = _new_attr[k]
_serialized = _serialized[k]
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise err
continue

except (AttributeError, KeyError, TypeError) as err:
Expand Down Expand Up @@ -776,6 +778,8 @@ def serialize_data(self, data, data_type, **kwargs):
data, data_type[1:-1], **kwargs)

except (ValueError, TypeError) as err:
if (isinstance(err, SerializationError)):
raise err # don't rewrap as SerializationError
msg = "Unable to serialize value: {!r} as type: {!r}."
raise_with_traceback(
SerializationError, msg.format(data, data_type), err)
Expand Down Expand Up @@ -858,7 +862,9 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
for d in data:
try:
serialized.append(self.serialize_data(d, iter_type, **kwargs))
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise err
serialized.append(None)

if div:
Expand Down Expand Up @@ -914,7 +920,9 @@ def serialize_dict(self, attr, dict_type, **kwargs):
try:
serialized[self.serialize_unicode(key)] = self.serialize_data(
value, dict_type, **kwargs)
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise err
serialized[self.serialize_unicode(key)] = None

if 'xml' in serialization_ctxt:
Expand Down
4 changes: 2 additions & 2 deletions msrest/universal_http/async_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(self, response: requests.Response, user_callback: Optional[Callable

async def __anext__(self):
try:
chunk = await trio.run_sync_in_worker_thread(
chunk = await trio.to_thread.run_sync(
_msrest_next,
self.iter_content_func,
)
Expand Down Expand Up @@ -209,7 +209,7 @@ async def send(self, request: ClientRequest, **kwargs: Any) -> AsyncClientRespon
session = kwargs.pop('session', self.session)

trio_limiter = kwargs.get("trio_limiter", None)
future = trio.run_sync_in_worker_thread(
future = trio.to_thread.run_sync(
functools.partial(
session.request,
request.method,
Expand Down
2 changes: 1 addition & 1 deletion msrest/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
# --------------------------------------------------------------------------

#: version of this package. Use msrest.__version__ instead
msrest_version = "0.6.21"
msrest_version = "0.7.0"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

setup(
name='msrest',
version='0.6.21',
version='0.7.0',
author='Microsoft Corporation',
packages=find_packages(exclude=["tests", "tests.*"]),
url=("https://github.com/Azure/msrest-for-python"),
Expand All @@ -53,6 +53,7 @@
"requests_oauthlib>=0.5.0",
"isodate>=0.6.0",
"certifi>=2017.4.17",
"azure-core>=1.24.0",
],
include_package_data=True,
package_data={
Expand Down
7 changes: 7 additions & 0 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from msrest.serialization import Model, last_restapi_key_transformer, full_restapi_key_transformer, rest_key_extractor
from msrest import Serializer, Deserializer
from msrest.exceptions import SerializationError, DeserializationError, ValidationError
from azure.core.exceptions import SerializationError as AzureCoreSerializationError, DeserializationError as AzureCoreDeserializationError

from . import storage_models

Expand Down Expand Up @@ -2579,5 +2580,11 @@ def __init__(self, name=None):
self.assertTrue(animal1!=animal2)
self.assertTrue(animal1==animal3)

class TestAzureCoreExceptions(unittest.TestCase):

def test_azure_core_exceptions(self):
self.assertEqual(SerializationError, AzureCoreSerializationError)
self.assertEqual(DeserializationError, AzureCoreDeserializationError)

if __name__ == '__main__':
unittest.main()