msrest-for-python
msrest-for-python copied to clipboard
msrest.serialization.Deserializer.deserialize_object() cannot handle subclasses
def deserialize_object(self, attr, **kwargs):
...
obj_type = type(attr)
...
if obj_type == dict:
The net effect is that when attr is a subclass of dict, the operation raises a TypeError, even though it could be deserialized as a dict.
Changing those if obj_type ==... checks to if isinstance(attr, ... would address this.
Could you give me a scenario when this would happen? Deserialization is based on json.loads, and this would never return a subclass of dict, so I assume you use it differently?
Sure, here's a real example: I have a subclass of dict for tags. It verifies that the key names and values are legit for Azure resource tags. When I try to supply this to a call to a begin_create_or_update, I get an exception because it cannot figure out how to serialize the dict subclass. json.dumps() handles this fine, but it blows up in deserialize_object because type != dict.