From 8b49a59aff5ac8c4a5df9fa99812347ffe650e1c Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 4 Dec 2023 11:17:13 -0800 Subject: [PATCH] Fix a traceback when the "repositories" option contains both strings and key/value pairs (#794). --- NEWS | 3 +++ borgmatic/config/normalize.py | 7 +++++-- setup.py | 2 +- tests/unit/config/test_normalize.py | 17 +++++------------ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 03f78bc..7efa967 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.8.6.dev0 + * #794: Fix a traceback when the "repositories" option contains both strings and key/value pairs. + 1.8.5 * #701: Add a "skip_actions" option to skip running particular actions, handy for append-only or checkless configurations. See the documentation for more information: diff --git a/borgmatic/config/normalize.py b/borgmatic/config/normalize.py index 1198bb5..cbad9a8 100644 --- a/borgmatic/config/normalize.py +++ b/borgmatic/config/normalize.py @@ -192,7 +192,7 @@ def normalize(config_filename, config): # Upgrade remote repositories to ssh:// syntax, required in Borg 2. repositories = config.get('repositories') if repositories: - if isinstance(repositories[0], str): + if any(isinstance(repository, str) for repository in repositories): logs.append( logging.makeLogRecord( dict( @@ -202,7 +202,10 @@ def normalize(config_filename, config): ) ) ) - config['repositories'] = [{'path': repository} for repository in repositories] + config['repositories'] = [ + {'path': repository} if isinstance(repository, str) else repository + for repository in repositories + ] repositories = config['repositories'] config['repositories'] = [] diff --git a/setup.py b/setup.py index e7893a8..f315f93 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.8.5' +VERSION = '1.8.6.dev0' setup( diff --git a/tests/unit/config/test_normalize.py b/tests/unit/config/test_normalize.py index ebe6874..699bb4d 100644 --- a/tests/unit/config/test_normalize.py +++ b/tests/unit/config/test_normalize.py @@ -216,6 +216,11 @@ def test_normalize_sections_with_only_scalar_raises(): {'repositories': [{'path': '/repo'}]}, True, ), + ( + {'repositories': [{'path': 'first'}, 'file:///repo']}, + {'repositories': [{'path': 'first'}, {'path': '/repo'}]}, + True, + ), ( {'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}]}, {'repositories': [{'path': 'ssh://foo@bar/repo', 'label': 'foo'}]}, @@ -251,15 +256,3 @@ def test_normalize_applies_hard_coded_normalization_to_config( assert logs else: assert logs == [] - - -def test_normalize_raises_error_if_repository_data_is_not_consistent(): - flexmock(module).should_receive('normalize_sections').and_return([]) - - with pytest.raises(TypeError): - module.normalize( - 'test.yaml', - { - 'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}, 'file:///repo'], - }, - )