diff --git a/compose/config/validation.py b/compose/config/validation.py index c6722a14d..940775a20 100644 --- a/compose/config/validation.py +++ b/compose/config/validation.py @@ -325,7 +325,6 @@ def _parse_oneof_validator(error): """ types = [] for context in error.context: - if context.validator == 'oneOf': _, error_msg = _parse_oneof_validator(context) return path_string(context.path), error_msg @@ -337,6 +336,13 @@ def _parse_oneof_validator(error): invalid_config_key = parse_key_from_error_msg(context) return (None, "contains unsupported option: '{}'".format(invalid_config_key)) + if context.validator == 'uniqueItems': + return ( + path_string(context.path) if context.path else None, + "contains non-unique items, please remove duplicates from {}".format( + context.instance), + ) + if context.path: return ( path_string(context.path), @@ -345,13 +351,6 @@ def _parse_oneof_validator(error): _parse_valid_types_from_validator(context.validator_value)), ) - if context.validator == 'uniqueItems': - return ( - None, - "contains non unique items, please remove duplicates from {}".format( - context.instance), - ) - if context.validator == 'type': types.append(context.validator_value) diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 14dd01179..de9a61302 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -581,6 +581,20 @@ class ConfigTest(unittest.TestCase): assert 'Invalid service name \'mong\\o\'' in excinfo.exconly() + def test_config_duplicate_cache_from_values_validation_error(self): + with pytest.raises(ConfigurationError) as exc: + config.load( + build_config_details({ + 'version': '2.3', + 'services': { + 'test': {'build': {'context': '.', 'cache_from': ['a', 'b', 'a']}} + } + + }) + ) + + assert 'build.cache_from contains non-unique items' in exc.exconly() + def test_load_with_multiple_files_v1(self): base_file = config.ConfigFile( 'base.yaml', @@ -2751,11 +2765,12 @@ class PortsTest(unittest.TestCase): def check_config(self, cfg): config.load( - build_config_details( - {'web': dict(image='busybox', **cfg)}, - 'working_dir', - 'filename.yml' - ) + build_config_details({ + 'version': '2.3', + 'services': { + 'web': dict(image='busybox', **cfg) + }, + }, 'working_dir', 'filename.yml') )