From 97714efde780d810628e7af67e3ea040005b90fb Mon Sep 17 00:00:00 2001 From: Philipp Herzog Date: Fri, 6 Sep 2024 11:58:49 +0200 Subject: [PATCH] relax require_one the require_one method would always raise a SilentConfigurationError on an empty list even if strict==False. Returning None in that case is more appropriate --- CHANGES.md | 2 +- src/batou/component.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4d65d94a..1901b7d4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ ## 2.5.1 (unreleased) --------------------- -- Nothing changed yet. +- fix Component.require_one raising a configuration error with strict=False ## 2.5.0 (2024-09-04) diff --git a/src/batou/component.py b/src/batou/component.py index 0e4548bd..65343f28 100644 --- a/src/batou/component.py +++ b/src/batou/component.py @@ -655,9 +655,9 @@ def require_one( key, host ) ) - elif len(resources) == 0: + elif len(resources) == 0 and strict: raise SilentConfigurationError() - return resources[0] + return resources[0] if resources else None def assert_cmd(self, *args, **kw): """Assert that given command returns successfully, raise