diff --git a/oslo_versionedobjects/base.py b/oslo_versionedobjects/base.py index b412b301..ac124acd 100644 --- a/oslo_versionedobjects/base.py +++ b/oslo_versionedobjects/base.py @@ -1147,7 +1147,11 @@ def obj_tree_get_versions(objname, tree=None): else: continue - obj_tree_get_versions(child_cls, tree=tree) + try: + obj_tree_get_versions(child_cls, tree=tree) + except IndexError: + raise exception.UnregisteredSubobject( + child_objname=child_cls, parent_objname=objname) return tree diff --git a/oslo_versionedobjects/exception.py b/oslo_versionedobjects/exception.py index 7b5be346..42222c38 100644 --- a/oslo_versionedobjects/exception.py +++ b/oslo_versionedobjects/exception.py @@ -186,3 +186,8 @@ class InvalidTargetVersion(VersionedObjectsException): class TargetBeforeSubobjectExistedException(VersionedObjectsException): msg_fmt = _("No subobject existed at version %(target_version)s") + + +class UnregisteredSubobject(VersionedObjectsException): + msg_fmt = _("%(child_objname)s is referenced by %(parent_objname)s but " + "is not registered") diff --git a/oslo_versionedobjects/tests/test_objects.py b/oslo_versionedobjects/tests/test_objects.py index 22f62d74..6856945a 100644 --- a/oslo_versionedobjects/tests/test_objects.py +++ b/oslo_versionedobjects/tests/test_objects.py @@ -2341,6 +2341,22 @@ class TestUtilityMethods(test.TestCase): 'TestChildTwo': '4.56'}, tree) + def test_missing_referenced(self): + """Ensure a missing child object is highlighted.""" + @base.VersionedObjectRegistry.register + class TestObjectFoo(base.VersionedObject): + VERSION = '1.23' + fields = { + # note that this object does not exist + 'child': fields.ObjectField('TestChildBar'), + } + + exc = self.assertRaises(exception.UnregisteredSubobject, + base.obj_tree_get_versions, + 'TestObjectFoo') + self.assertIn('TestChildBar is referenced by TestObjectFoo', + exc.format_message()) + class TestListObjectConcat(test.TestCase): def test_list_object_concat(self):