Fix traceback when a database hook value is null in a configuration file (#355).

This commit is contained in:
Dan Helfman 2020-10-07 15:41:45 -07:00
parent d06c1f2943
commit 0e978299cf
4 changed files with 16 additions and 3 deletions

1
NEWS
View file

@ -1,6 +1,7 @@
1.5.11.dev0 1.5.11.dev0
* #341: Add "temporary_directory" option for changing Borg's temporary directory. * #341: Add "temporary_directory" option for changing Borg's temporary directory.
* #352: Lock down systemd security settings in sample systemd service file. * #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 1.5.10
* #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract". * #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract".

View file

@ -658,7 +658,9 @@ def collect_configuration_run_summary_logs(configs, arguments):
if not configs: if not configs:
yield from make_error_log_records( 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 return

View file

@ -58,5 +58,5 @@ def call_hooks(function_name, hooks, log_prefix, hook_names, *args, **kwargs):
return { return {
hook_name: call_hook(function_name, hooks, log_prefix, hook_name, *args, **kwargs) hook_name: call_hook(function_name, hooks, log_prefix, hook_name, *args, **kwargs)
for hook_name in hook_names for hook_name in hook_names
if hook_name in hooks if hooks.get(hook_name)
} }

View file

@ -58,7 +58,7 @@ def test_call_hooks_calls_each_hook_and_collects_return_values():
assert return_values == expected_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()} hooks = {'super_hook': flexmock()}
expected_return_values = {'super_hook': flexmock()} expected_return_values = {'super_hook': flexmock()}
flexmock(module).should_receive('call_hook').and_return(expected_return_values['super_hook']) 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) return_values = module.call_hooks('do_stuff', hooks, 'prefix', ('super_hook', 'other_hook'), 55)
assert return_values == expected_return_values 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