config add: fix parsing of validator error to infer type from oneOf (#29475)
This commit is contained in:
parent
560abdc46d
commit
dba7a03daa
2 changed files with 10 additions and 4 deletions
|
@ -1099,11 +1099,11 @@ def get_valid_type(path):
|
|||
jsonschema_error = e.validation_error
|
||||
if jsonschema_error.validator == 'type':
|
||||
return types[jsonschema_error.validator_value]()
|
||||
elif jsonschema_error.validator == 'anyOf':
|
||||
elif jsonschema_error.validator in ('anyOf', 'oneOf'):
|
||||
for subschema in jsonschema_error.validator_value:
|
||||
anyof_type = subschema.get('type')
|
||||
if anyof_type is not None:
|
||||
return types[anyof_type]()
|
||||
schema_type = subschema.get('type')
|
||||
if schema_type is not None:
|
||||
return types[schema_type]()
|
||||
else:
|
||||
return type(None)
|
||||
raise ConfigError("Cannot determine valid type for path '%s'." % path)
|
||||
|
|
|
@ -239,6 +239,12 @@ def test_config_add_ordered_dict(mutable_empty_config):
|
|||
"""
|
||||
|
||||
|
||||
def test_config_add_interpret_oneof(mutable_empty_config):
|
||||
# Regression test for a bug that would raise a validation error
|
||||
config('add', 'packages:all:target:[x86_64]')
|
||||
config('add', 'packages:all:variants:~shared')
|
||||
|
||||
|
||||
def test_config_add_invalid_fails(mutable_empty_config):
|
||||
config('add', 'packages:all:variants:+debug')
|
||||
with pytest.raises(
|
||||
|
|
Loading…
Reference in a new issue