From dba7a03daacee4d2749fe66719455b10a5ecb8ef Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Mon, 21 Mar 2022 08:55:02 -0700 Subject: [PATCH] config add: fix parsing of validator error to infer type from oneOf (#29475) --- lib/spack/spack/config.py | 8 ++++---- lib/spack/spack/test/cmd/config.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 822d674807..2761be01ed 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -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) diff --git a/lib/spack/spack/test/cmd/config.py b/lib/spack/spack/test/cmd/config.py index e8dc80c6da..4b63994618 100644 --- a/lib/spack/spack/test/cmd/config.py +++ b/lib/spack/spack/test/cmd/config.py @@ -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(