From 0e978299cfd46b98a2e45977e28d88d1412b1e1e Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 7 Oct 2020 15:41:45 -0700 Subject: [PATCH] Fix traceback when a database hook value is null in a configuration file (#355). --- NEWS | 1 + borgmatic/commands/borgmatic.py | 4 +++- borgmatic/hooks/dispatch.py | 2 +- tests/unit/hooks/test_dispatch.py | 12 +++++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 1de4156..a3e5d83 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 1.5.11.dev0 * #341: Add "temporary_directory" option for changing Borg's temporary directory. * #352: Lock down systemd security settings in sample systemd service file. + * #355: Fix traceback when a database hook value is null in a configuration file. 1.5.10 * #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract". diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index a6df97b..1f41f4e 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -658,7 +658,9 @@ def collect_configuration_run_summary_logs(configs, arguments): if not configs: yield from make_error_log_records( - '{}: No configuration files found'.format(' '.join(arguments['global'].config_paths)) + '{}: No valid configuration files found'.format( + ' '.join(arguments['global'].config_paths) + ) ) return diff --git a/borgmatic/hooks/dispatch.py b/borgmatic/hooks/dispatch.py index 6c05cad..6fb2c80 100644 --- a/borgmatic/hooks/dispatch.py +++ b/borgmatic/hooks/dispatch.py @@ -58,5 +58,5 @@ def call_hooks(function_name, hooks, log_prefix, hook_names, *args, **kwargs): return { hook_name: call_hook(function_name, hooks, log_prefix, hook_name, *args, **kwargs) for hook_name in hook_names - if hook_name in hooks + if hooks.get(hook_name) } diff --git a/tests/unit/hooks/test_dispatch.py b/tests/unit/hooks/test_dispatch.py index ec163d8..7224e19 100644 --- a/tests/unit/hooks/test_dispatch.py +++ b/tests/unit/hooks/test_dispatch.py @@ -58,7 +58,7 @@ def test_call_hooks_calls_each_hook_and_collects_return_values(): assert return_values == expected_return_values -def test_call_hooks_calls_skips_return_values_for_unconfigured_hooks(): +def test_call_hooks_calls_skips_return_values_for_missing_hooks(): hooks = {'super_hook': flexmock()} expected_return_values = {'super_hook': flexmock()} flexmock(module).should_receive('call_hook').and_return(expected_return_values['super_hook']) @@ -66,3 +66,13 @@ def test_call_hooks_calls_skips_return_values_for_unconfigured_hooks(): return_values = module.call_hooks('do_stuff', hooks, 'prefix', ('super_hook', 'other_hook'), 55) assert return_values == expected_return_values + + +def test_call_hooks_calls_skips_return_values_for_null_hooks(): + hooks = {'super_hook': flexmock(), 'other_hook': None} + expected_return_values = {'super_hook': flexmock()} + flexmock(module).should_receive('call_hook').and_return(expected_return_values['super_hook']) + + return_values = module.call_hooks('do_stuff', hooks, 'prefix', ('super_hook', 'other_hook'), 55) + + assert return_values == expected_return_values