diff --git a/nova/objects/base.py b/nova/objects/base.py index 2f6c649046cc..e5b6349f03eb 100644 --- a/nova/objects/base.py +++ b/nova/objects/base.py @@ -505,6 +505,12 @@ class ObjectListBase(object): # requested of the list object. child_versions = {} + def __init__(self, *args, **kwargs): + super(ObjectListBase, self).__init__(*args, **kwargs) + if 'objects' not in kwargs: + self.objects = [] + self._changed_fields.discard('objects') + def __iter__(self): """List iterator interface.""" return iter(self.objects) diff --git a/nova/tests/objects/test_objects.py b/nova/tests/objects/test_objects.py index 48ccadc55224..7ac81219d5ee 100644 --- a/nova/tests/objects/test_objects.py +++ b/nova/tests/objects/test_objects.py @@ -812,6 +812,17 @@ class TestObjectListBase(test.TestCase): # This should now look clean because the child is clean self.assertEqual(set(), obj.obj_what_changed()) + def test_initialize_objects(self): + class Foo(base.ObjectListBase, base.NovaObject): + fields = {'objects': fields.ListOfObjectsField('Bar')} + + class Bar(base.NovaObject): + fields = {'foo': fields.StringField()} + + obj = Foo() + self.assertEqual([], obj.objects) + self.assertEqual(set(), obj.obj_what_changed()) + class TestObjectSerializer(_BaseTestCase): def test_serialize_entity_primitive(self):