From 6c136ebbf1a99e5937f77017ba2e0977ba56df77 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 16 Jun 2019 21:33:40 -0700 Subject: [PATCH] Fix for unclear error message for invalid YAML merge include (#196). --- NEWS | 3 +++ borgmatic/config/load.py | 4 +--- docs/how-to/make-per-application-backups.md | 4 ++++ setup.py | 2 +- tests/integration/config/test_load.py | 22 +++++++++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 28c2a07..dd9c7a1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.3.7.dev0 + * #196: Fix for unclear error message for invalid YAML merge include. + 1.3.6 * #53: Log to syslog in addition to existing console logging. Add --syslog-verbosity flag to customize the log level. See the documentation for more information: diff --git a/borgmatic/config/load.py b/borgmatic/config/load.py index 8339dfb..b2c2e27 100644 --- a/borgmatic/config/load.py +++ b/borgmatic/config/load.py @@ -54,9 +54,7 @@ class Include_constructor(ruamel.yaml.SafeConstructor): for index, (key_node, value_node) in enumerate(node.value): if key_node.tag == u'tag:yaml.org,2002:merge' and value_node.tag == '!include': - included_value = representer.represent_mapping( - tag='tag:yaml.org,2002:map', mapping=self.construct_object(value_node) - ) + included_value = representer.represent_data(self.construct_object(value_node)) node.value[index] = (key_node, included_value) super(Include_constructor, self).flatten_mapping(node) diff --git a/docs/how-to/make-per-application-backups.md b/docs/how-to/make-per-application-backups.md index 08a2ad0..0333c33 100644 --- a/docs/how-to/make-per-application-backups.md +++ b/docs/how-to/make-per-application-backups.md @@ -105,6 +105,10 @@ include, the local file's option takes precedent. And note that this is a shallow merge rather than a deep merge, so the merging does not descend into nested values. +Note that this `<<` include merging syntax is only for merging in mappings +(keys/values). If you'd like to include other types like scalars or lists +directly, please see the section above about standard includes. + ## Related documentation diff --git a/setup.py b/setup.py index a47125d..a47e148 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.3.6' +VERSION = '1.3.7.dev0' setup( diff --git a/tests/integration/config/test_load.py b/tests/integration/config/test_load.py index bcaae59..521e92d 100644 --- a/tests/integration/config/test_load.py +++ b/tests/integration/config/test_load.py @@ -1,5 +1,7 @@ import sys +import pytest +import ruamel.yaml from flexmock import flexmock from borgmatic.config import load as module @@ -38,3 +40,23 @@ def test_load_configuration_merges_include(): ) assert module.load_configuration('config.yaml') == {'foo': 'override', 'baz': 'quux'} + + +def test_load_configuration_does_not_merge_include_list(): + builtins = flexmock(sys.modules['builtins']) + builtins.should_receive('open').with_args('include.yaml').and_return( + ''' + - one + - two + ''' + ) + builtins.should_receive('open').with_args('config.yaml').and_return( + ''' + foo: bar + repositories: + <<: !include include.yaml + ''' + ) + + with pytest.raises(ruamel.yaml.error.YAMLError): + assert module.load_configuration('config.yaml')