Merge "Modify VO so that obj.get always defaults to None"
This commit is contained in:
commit
8c4081bfa8
@ -256,7 +256,13 @@ class CinderObjectDictCompat(base.VersionedObjectDictCompat):
|
||||
not self.obj_attr_is_set(key)):
|
||||
return value
|
||||
else:
|
||||
return getattr(self, key)
|
||||
try:
|
||||
return getattr(self, key)
|
||||
except (exception.ObjectActionError, NotImplementedError):
|
||||
# Exception when haven't set a value for non-lazy
|
||||
# loadable attribute, but to mimic typical dict 'get'
|
||||
# behavior we should still return None
|
||||
return None
|
||||
|
||||
def __contains__(self, name):
|
||||
try:
|
||||
|
@ -587,6 +587,7 @@ class TestCinderDictObject(test_objects.BaseObjectsTestCase):
|
||||
obj = self.TestDictObject()
|
||||
self.assertIsNone(obj.get('non_existing'))
|
||||
self.assertEqual('val', obj.get('abc', 'val'))
|
||||
self.assertIsNone(obj.get('abc'))
|
||||
obj.abc = 'val2'
|
||||
self.assertEqual('val2', obj.get('abc', 'val'))
|
||||
self.assertEqual(42, obj.get('foo'))
|
||||
|
Loading…
Reference in New Issue
Block a user