xlab-steampunk / redfish-client-python

Minimalistic Redfish API client
Apache License 2.0
4 stars 8 forks source link

Resource.__getattr__ does not properly raise an AttributeError if a Key is not present #35

Closed jkugler closed 2 years ago

jkugler commented 2 years ago

The Resource class currently has this code:

    def __getattr__(self, name):
        return self[name]

    def __getitem__(self, name):
        if name in self._content:
            return self._build(self._content[name])
        return self._build(self._get_content()[name])

If name is not in self._build(self._get_content() it raises a KeyError, which propagates upward. However, __getattr__ should raise an AttributeError if an attribute doesn't exist.

This causes a KeyError to be raised when calling code like hasattr(resource_object, 'some_attribute) instead of returning false.