From c9f20eb26003bc4611b4823e50568b05a7c4b835 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 15 Feb 2024 21:12:42 -0800 Subject: [PATCH] Fix "--override" values containing deprecated section headers not actually overriding configuration options under deprecated section headers (#829). --- NEWS | 2 ++ borgmatic/config/override.py | 7 ++++++- tests/integration/config/test_override.py | 4 ++++ tests/integration/config/test_validate.py | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 054142c..e89cce6 100644 --- a/NEWS +++ b/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. diff --git a/borgmatic/config/override.py b/borgmatic/config/override.py index d1ab127..8a60cb5 100644 --- a/borgmatic/config/override.py +++ b/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) diff --git a/tests/integration/config/test_override.py b/tests/integration/config/test_override.py index bcf3d09..a09380c 100644 --- a/tests/integration/config/test_override.py +++ b/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', } diff --git a/tests/integration/config/test_validate.py b/tests/integration/config/test_validate.py index e438b48..b0c8712 100644 --- a/tests/integration/config/test_validate.py +++ b/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 == {