Bläddra i källkod

Fix "--override" values containing deprecated section headers not actually overriding configuration options under deprecated section headers (#829).

Dan Helfman 1 år sedan
förälder
incheckning
c9f20eb260

+ 2 - 0
NEWS

@@ -1,6 +1,8 @@
 1.8.9.dev0
  * #827: When the "--json" flag is given, suppress console escape codes so as not to
    interfere with JSON output.
+ * #829: Fix "--override" values containing deprecated section headers not actually overriding
+   configuration options under deprecated section headers.
  * Clarify documentation about restoring a database: borgmatic does not create the database upon
    restore.
 

+ 6 - 1
borgmatic/config/override.py

@@ -103,7 +103,7 @@ def parse_overrides(raw_overrides, schema):
     for raw_override in raw_overrides:
         try:
             raw_keys, value = raw_override.split('=', 1)
-            keys = strip_section_names(tuple(raw_keys.split('.')))
+            keys = tuple(raw_keys.split('.'))
             option_type = type_for_option(schema, keys)
 
             parsed_overrides.append(
@@ -127,8 +127,13 @@ def apply_overrides(config, schema, raw_overrides):
     Given a configuration dict, a corresponding configuration schema dict, and a sequence of
     configuration file override strings in the form of "option.suboption=value", parse each override
     and set it into the configuration dict.
+
+    Set the overrides into the configuration both with and without deprecated section names (if
+    used), so that the overrides work regardless of whether the configuration is also using
+    deprecated section names.
     '''
     overrides = parse_overrides(raw_overrides, schema)
 
     for keys, value in overrides:
         set_values(config, keys, value)
+        set_values(config, strip_section_names(keys), value)

+ 4 - 0
tests/integration/config/test_override.py

@@ -29,6 +29,7 @@ def test_apply_overrides_updates_config():
         'section.key=value1',
         'other_section.thing=value2',
         'section.nested.key=value3',
+        'location.no_longer_in_location=value4',
         'new.foo=bar',
         'new.mylist=[baz]',
         'new.nonlist=[quux]',
@@ -36,6 +37,7 @@ def test_apply_overrides_updates_config():
     config = {
         'section': {'key': 'value', 'other': 'other_value'},
         'other_section': {'thing': 'thing_value'},
+        'no_longer_in_location': 'because_location_is_deprecated',
     }
     schema = {
         'properties': {
@@ -49,4 +51,6 @@ def test_apply_overrides_updates_config():
         'section': {'key': 'value1', 'other': 'other_value', 'nested': {'key': 'value3'}},
         'other_section': {'thing': 'value2'},
         'new': {'foo': 'bar', 'mylist': ['baz'], 'nonlist': '[quux]'},
+        'location': {'no_longer_in_location': 'value4'},
+        'no_longer_in_location': 'value4',
     }

+ 1 - 1
tests/integration/config/test_validate.py

@@ -241,7 +241,7 @@ def test_parse_configuration_applies_overrides():
     )
 
     config, config_paths, logs = module.parse_configuration(
-        '/tmp/config.yaml', '/tmp/schema.yaml', overrides=['location.local_path=borg2']
+        '/tmp/config.yaml', '/tmp/schema.yaml', overrides=['local_path=borg2']
     )
 
     assert config == {