Azure / msrest-for-python

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

serialize_enum should not accept the wrong type #38

Closed lmazuel closed 7 years ago

lmazuel commented 7 years ago

Example:

        test_obj = type("TestEnumObj", (Model,), {"_attribute_map":None})
        test_obj._attribute_map = {
            "abc":{"key":"ABC", "type":"TestEnum"}
        }
        class TestEnum(Enum):
            val = "Value"

        class TestEnum2(Enum):
            val2 = "Value2"

        t = test_obj
        t.abc = TestEnum2.val2

        serializer = Serializer({
            'TestEnum': TestEnum,
            'TestEnum2': TestEnum2
        })

        serializer._serialize(t) # Should fail

Currently there is no type check, it just looks like an enum and we are happy. We should check if it's the correct enum, or least that the value is consistent.

Currently, the server will fail with probably a more complexe error message to handle that we can do

FYI @johanste