Merge "Modify VO so that obj.get always defaults to None"

This commit is contained in:
Jenkins 2015-12-28 22:46:48 +00:00 committed by Gerrit Code Review
commit 8c4081bfa8
2 changed files with 8 additions and 1 deletions

View File

@ -256,7 +256,13 @@ class CinderObjectDictCompat(base.VersionedObjectDictCompat):
not self.obj_attr_is_set(key)):
return value
else:
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:

View File

@ -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'))