I am using the microsoft graph SDK for CRUD operations on resources like mails, contacts, calendarevents etc.
The graph API uses patch for updating datasets. At the same time, the SDK provides models for all resources available via the Graph API and you are strongly encouraged to use them.
The problem is, that those models are typed dataclasses. Meaning right from instantiation, the class has all defined attributes, those you set are filled, all others are None by default. Initially I assumed, that the sdk or the graph api ignores values set to None by default, but it does not. So whenever I use the provided models for a patch operation and only fill them with the data that is supposed to be updated, it will update this data and everything else gets updated to "None".
For instance when I have a contact like:
Surname: Homer
Name: Simpson
Occupation: Controller at Springfield Nuclear Plant
And I now update Homers Occupation because he switches jobs again then the SDKs Contact Object will look like this:
Surname: None
Name: None
Occupation: Astronaut
And since its a patch operation, it will also update my dataset on MS Graph with those None values.
What I have tried so far:
- A lot of research in the SDKs Git repository and many LLMs.
- Converting the Object into a dictionary to delete None values. This is possible but a lot of those objects have other nested objects and when you later try to serialise this dictionary, Python is unable to do this. The SDK comes with its own serialiser, but when you make any changes to the provides models it often is unable to serialise them.
This feels like a catch 22 because the models provided can not be changed without breaking the serialiser, but they also can not be left with all those None values because they break the patch operation.
EDIT: I was asked to provide python code. But the question is not about my code but about the python implementation of the graph sdk and the apis behaviour. So please find attached for reference: https://github.com/microsoftgraph/msgraph-sdk-python/tree/main
postmethod?