summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2022-03-21 08:55:02 -0700
committerMassimiliano Culpo <massimiliano.culpo@gmail.com>2022-04-14 11:08:17 +0200
commitad2c0208487daee84892e81ed248360a3feb4226 (patch)
tree8a31819cda738ae811041523688f99bc88b9091c /lib
parentbd119927ff95ed2cf2e3625ef6021ebb01a20d1f (diff)
downloadspack-ad2c0208487daee84892e81ed248360a3feb4226.tar.gz
spack-ad2c0208487daee84892e81ed248360a3feb4226.tar.bz2
spack-ad2c0208487daee84892e81ed248360a3feb4226.tar.xz
spack-ad2c0208487daee84892e81ed248360a3feb4226.zip
config add: fix parsing of validator error to infer type from oneOf (#29475)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/config.py8
-rw-r--r--lib/spack/spack/test/cmd/config.py6
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
index f3fc73e4b4..da19aab2dc 100644
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -1090,11 +1090,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 63c3cab92a..bf77d78133 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(