Merge "Raise exception when synthetic field invalid"
This commit is contained in:
commit
4f818482ab
@ -290,6 +290,11 @@ class DeclarativeObject(abc.ABCMeta):
|
|||||||
if 'project_id' in cls.fields and 'tenant_id' not in cls.fields:
|
if 'project_id' in cls.fields and 'tenant_id' not in cls.fields:
|
||||||
cls.extra_filter_names.add('tenant_id')
|
cls.extra_filter_names.add('tenant_id')
|
||||||
|
|
||||||
|
invalid_fields = [f for f in cls.synthetic_fields
|
||||||
|
if f not in cls.fields]
|
||||||
|
if invalid_fields:
|
||||||
|
raise o_exc.NeutronObjectValidatorException(fields=invalid_fields)
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(DeclarativeObject)
|
@six.add_metaclass(DeclarativeObject)
|
||||||
class NeutronDbObject(NeutronObject):
|
class NeutronDbObject(NeutronObject):
|
||||||
|
@ -1991,3 +1991,24 @@ class OperationOnStringAndJsonTestCase(test_base.BaseTestCase):
|
|||||||
res = base.NeutronDbObject.filter_to_json_str(field_val,
|
res = base.NeutronDbObject.filter_to_json_str(field_val,
|
||||||
default_val)
|
default_val)
|
||||||
self.assertEqual(default_val, res)
|
self.assertEqual(default_val, res)
|
||||||
|
|
||||||
|
|
||||||
|
class NeutronObjectValidatorTestCase(test_base.BaseTestCase):
|
||||||
|
|
||||||
|
def test_load_wrong_synthetic_fields(self):
|
||||||
|
try:
|
||||||
|
@obj_base.VersionedObjectRegistry.register_if(False)
|
||||||
|
class FakeNeutronObjectSyntheticFieldWrong(base.NeutronDbObject):
|
||||||
|
# Version 1.0: Initial version
|
||||||
|
VERSION = '1.0'
|
||||||
|
|
||||||
|
db_model = FakeModel
|
||||||
|
|
||||||
|
fields = {
|
||||||
|
'id': common_types.UUIDField(),
|
||||||
|
'obj_field': common_types.UUIDField()
|
||||||
|
}
|
||||||
|
|
||||||
|
synthetic_fields = ['obj_field', 'wrong_synthetic_field_name']
|
||||||
|
except o_exc.NeutronObjectValidatorException as exc:
|
||||||
|
self.assertIn('wrong_synthetic_field_name', str(exc))
|
||||||
|
Loading…
Reference in New Issue
Block a user