Skip to content

Commit e813e06

Browse files
authored
Fix unicode as object type (#222)
* Fix unicode as object type * Changelog
1 parent 1187350 commit e813e06

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Release History
2626
**Bugfixes**
2727

2828
- Fix serialization of random Model object #220
29+
- Fix serialization of unicode string in Py2 and object mode #221
2930

3031

3132
2020-07-27 Version 0.6.18

msrest/serialization.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,8 @@ def serialize_object(self, attr, **kwargs):
951951
return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs)
952952
if obj_type is _long_type:
953953
return self.serialize_long(attr)
954+
if obj_type is unicode_str:
955+
return self.serialize_unicode(attr)
954956

955957
# If it's a model or I know this dependency, serialize as a Model
956958
elif obj_type in self.dependencies.values() or isinstance(attr, Model):

tests/test_serialization.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,8 @@ def test_long_as_type_object(self):
13661366
except NameError:
13671367
long_type = int
13681368

1369+
s = Serializer()
1370+
assert s.serialize_data(long_type(1), 'object') == long_type(1)
13691371

13701372
class TestModel(Model):
13711373
_attribute_map = {'data': {'key': 'data', 'type': 'object'}}
@@ -1376,6 +1378,23 @@ class TestModel(Model):
13761378
'data': {'id': long_type(1)}
13771379
}
13781380

1381+
def test_unicode_as_type_object(self):
1382+
"""Test irrelevant on Python 3. But still doing it to test regresssion.
1383+
https://github.com/Azure/msrest-for-python/issue/221
1384+
"""
1385+
1386+
s = Serializer()
1387+
assert s.serialize_data(u"\ua015", 'object') == u"\ua015"
1388+
1389+
class TestModel(Model):
1390+
_attribute_map = {'data': {'key': 'data', 'type': 'object'}}
1391+
1392+
m = TestModel(data = {'id': u"\ua015"})
1393+
serialized = m.serialize()
1394+
assert serialized == {
1395+
'data': {'id': u"\ua015"}
1396+
}
1397+
13791398
def test_json_with_xml_map(self):
13801399
basic_json = {'age': 37, 'country': 'france'}
13811400

0 commit comments

Comments
 (0)