Share via

Missing enum value in MS Graph metadata, affecting SDKs

Virnik 20 Reputation points
2023-11-04T21:01:01.61+00:00

Hi,
I'm using MS Graph via the python SDK, and I'm getting exceptions when parsing the response from the API, since the value returned does not match the metadata XML of the API.

Please find more details here: https://github.com/microsoftgraph/msgraph-sdk-python/issues/415

Microsoft Security | Microsoft Graph
0 comments No comments

Answer accepted by question author

Danstan Onyango 3,996 Reputation points Microsoft Employee
2023-12-19T07:41:28.4633333+00:00

It seems that the issue is related to a missing enum value in the MS Graph metadata, which is affecting SDKs. According to the GitHub thread you shared, the issue has been acknowledged and there is WIP on fixing it. In the meantime, one possible workaround is to modify the SDK code to handle the missing enum value. Here's an example of how you can modify the ModelDeserializer class in the msgraph.serializer module to handle the issue:

from msgraph.serializer import ModelDeserializer

from msgraph.model import EnumBase

class CustomModelDeserializer(ModelDeserializer):
    def deserialize(self, response, cls, **kwargs):
        if issubclass(cls, EnumBase):
            # Handle missing enum value
            if response.text == 'MissingValue':
                return None
        return super().deserialize(response, cls, **kwargs)

This code creates a custom ModelDeserializer class that checks if the class being deserialized is an EnumBase subclass (which should be the case for enums in the MS Graph SDK). If it is, the code checks if the response value is 'MissingValue' (which is the missing enum value mentioned in the GitHub thread). If it is, the code returns None instead of trying to deserialize the value. Otherwise, the code calls the deserialize method of the base class to deserialize the value as usual. You can then use this custom ModelDeserializer class instead of the default one in your code:

from msgraph.serializer import Serializer
# Create a custom serializer with the custom deserializer
serializer = Serializer(deserializer=CustomModelDeserializer())
# Use the custom serializer to deserialize the response
response_data = serializer.deserialize(response, MyModelClass)

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.