config add: fix parsing of validator error to infer type from oneOf (#29475)
This commit is contained in:
parent
560abdc46d
commit
dba7a03daa
@ -1099,11 +1099,11 @@ def get_valid_type(path):
|
|||||||
jsonschema_error = e.validation_error
|
jsonschema_error = e.validation_error
|
||||||
if jsonschema_error.validator == 'type':
|
if jsonschema_error.validator == 'type':
|
||||||
return types[jsonschema_error.validator_value]()
|
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:
|
for subschema in jsonschema_error.validator_value:
|
||||||
anyof_type = subschema.get('type')
|
schema_type = subschema.get('type')
|
||||||
if anyof_type is not None:
|
if schema_type is not None:
|
||||||
return types[anyof_type]()
|
return types[schema_type]()
|
||||||
else:
|
else:
|
||||||
return type(None)
|
return type(None)
|
||||||
raise ConfigError("Cannot determine valid type for path '%s'." % path)
|
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):
|
def test_config_add_invalid_fails(mutable_empty_config):
|
||||||
config('add', 'packages:all:variants:+debug')
|
config('add', 'packages:all:variants:+debug')
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
|
Loading…
Reference in New Issue
Block a user