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

This commit is contained in:
Dan Helfman 2024-02-15 21:12:42 -08:00
parent f4744826fe
commit c9f20eb260
4 changed files with 13 additions and 2 deletions

2
NEWS
View file

@ -1,6 +1,8 @@
1.8.9.dev0 1.8.9.dev0
* #827: When the "--json" flag is given, suppress console escape codes so as not to * #827: When the "--json" flag is given, suppress console escape codes so as not to
interfere with JSON output. 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 * Clarify documentation about restoring a database: borgmatic does not create the database upon
restore. restore.

View file

@ -103,7 +103,7 @@ def parse_overrides(raw_overrides, schema):
for raw_override in raw_overrides: for raw_override in raw_overrides:
try: try:
raw_keys, value = raw_override.split('=', 1) 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) option_type = type_for_option(schema, keys)
parsed_overrides.append( 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 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 configuration file override strings in the form of "option.suboption=value", parse each override
and set it into the configuration dict. 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) overrides = parse_overrides(raw_overrides, schema)
for keys, value in overrides: for keys, value in overrides:
set_values(config, keys, value) set_values(config, keys, value)
set_values(config, strip_section_names(keys), value)

View file

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

View file

@ -241,7 +241,7 @@ def test_parse_configuration_applies_overrides():
) )
config, config_paths, logs = module.parse_configuration( 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 == { assert config == {