Browse Source

Fix for unclear error message for invalid YAML merge include (#196).

Dan Helfman 6 years ago
parent
commit
6c136ebbf1
5 changed files with 31 additions and 4 deletions
  1. 3 0
      NEWS
  2. 1 3
      borgmatic/config/load.py
  3. 4 0
      docs/how-to/make-per-application-backups.md
  4. 1 1
      setup.py
  5. 22 0
      tests/integration/config/test_load.py

+ 3 - 0
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:

+ 1 - 3
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)

+ 4 - 0
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
 

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.3.6'
+VERSION = '1.3.7.dev0'
 
 
 setup(

+ 22 - 0
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')