WebexCommunity/WebexPythonSDK

ImmutableData.to_dict keys may not match object attributes

baryonyx5 opened this issue · 1 comments

I'm not sure this qualifies as a bug but I thought it worth mentioning...

A good example of this is the License API where attributes like siteUrl, subscriptionId may or may not exist in the response json depending on the license type.

The License instance will always have these attributes because the Mixin class has a property defined for them (which will return None if it doesn't exist in the json data).

I think most users will assume to_dict() will return a dictionary with keys matching the data attributes on the object. Especially since there is a separate json_data property to access the original response.

One way to address this would be to move the to_dict method to each mixin class and do something like:

def to_dict(self):
    return {k: getattr(self, k) for k in dir(LicenseBasicPropertiesMixin)}

Although this would result in the returned dictionary containing converted values (WebexTeamsDateTime for instance), which would be a change from the current behavior.

If this is something you think is worth addressing. I'd be happy to provide a PR.