diff --git a/python/cm/checker.py b/python/cm/checker.py index efabfb0901..bfa5e2bda1 100644 --- a/python/cm/checker.py +++ b/python/cm/checker.py @@ -119,8 +119,8 @@ def match_list(data, rules, rule, path, parent=None): def match_dict(data, rules, rule, path, parent=None): check_match_type("match_dict", data, dict, path, rule, parent) - if "required_items" in rules[rule] or "invisible_items" in rules[rule]: - for i in rules[rule].get("required_items", []) + rules[rule].get("invisible_items", []): + if "required_items" in rules[rule]: + for i in rules[rule].get("required_items", []): if i not in data: raise FormatError(path, f'There is no required key "{i}" in map.', data, rule) diff --git a/python/cm/tests/test_yaml_checker.py b/python/cm/tests/test_yaml_checker.py index e871797ce8..3fd3fe3b49 100644 --- a/python/cm/tests/test_yaml_checker.py +++ b/python/cm/tests/test_yaml_checker.py @@ -69,11 +69,10 @@ class TestYAMLChecker(TestCase): def test_initial_data_correct_success(self): process_rule(data=test_data, rules=test_rules, name="root") - def test_invisible_field_not_in_data_fail(self): + def test_invisible_field_not_in_data_success(self): rules = deepcopy(test_rules) rules["replica_item"]["invisible_items"].append("non_existent_field") - with self.assertRaises(FormatError): - process_rule(data=test_data, rules=rules, name="root") + process_rule(data=test_data, rules=rules, name="root") def test_invisible_items_in_match_none_fail(self): rules = deepcopy(test_rules)