Azure / msrest-for-python

The runtime library "msrest" for AutoRest generated Python clients.
MIT License
41 stars 64 forks source link

msrest.serialization.Deserializer.deserialize_object() cannot handle subclasses #245

Open jazelenk opened 2 years ago

jazelenk commented 2 years ago
    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.

lmazuel commented 2 years ago

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?

jazelenk commented 2 years ago

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.