from cinder import context
from cinder import exception
-from cinder.i18n import _, _LE
+from cinder.i18n import _, _LE, _LW
from cinder import objects
from cinder.objects import fields
from cinder.openstack.common import log as logging
NOTE(danms): May be removed in the future.
"""
if key not in self.obj_fields:
- raise AttributeError("'%s' object has no attribute '%s'" % (
- self.__class__, key))
+ # NOTE(jdg): There are a number of places where we rely on the
+ # old dictionary version and do a get(xxx, None).
+ # The following preserves that compatability but in
+ # the future we'll remove this shim altogether so don't
+ # rely on it.
+ LOG.warning(_LW('Cinder object %(object_name)s has no '
+ 'attribute named: %(attribute_name)s'),
+ {'object_name': self.__class__.__name__,
+ 'attribute_name': key})
+ return None
if value != NotSpecifiedSentinel and not self.obj_attr_is_set(key):
return value
else:
self.assertEqual('loaded!', obj.get('bar'))
# Bar now has a default, but loaded value should be returned
self.assertEqual('loaded!', obj.get('bar', 'not-loaded'))
- # Invalid attribute should raise AttributeError
- self.assertRaises(AttributeError, obj.get, 'nothing')
- # ...even with a default
- self.assertRaises(AttributeError, obj.get, 'nothing', 3)
+ # Invalid attribute should return None
+ self.assertEqual(None, obj.get('nothing'))
def test_object_inheritance(self):
base_fields = base.CinderPersistentObject.fields.keys()