From ee80c5f20300c89f76c7fff230a92aace868b78f Mon Sep 17 00:00:00 2001 From: Allen Robel Date: Fri, 10 Oct 2025 14:28:18 -1000 Subject: [PATCH 1/2] Log: fix bad append to string validate_logging_config(): fix case where we were appending to msg rather than initializing it. --- lib/nd_python/common/log_v2.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/nd_python/common/log_v2.py b/lib/nd_python/common/log_v2.py index c59e959..2161d6a 100644 --- a/lib/nd_python/common/log_v2.py +++ b/lib/nd_python/common/log_v2.py @@ -291,7 +291,7 @@ def validate_logging_config(self, logging_config: dict) -> None: ``` """ if len(logging_config.get("handlers", {})) == 0: - msg = "logging.config.dictConfig: " + msg: str = "logging.config.dictConfig: " msg += "No file handlers found. " msg += "Add a file handler to the logging config file " msg += f"and try again: {self.config}" @@ -299,15 +299,15 @@ def validate_logging_config(self, logging_config: dict) -> None: bad_handlers = [] for handler in logging_config.get("handlers", {}): if handler not in self.valid_handlers: - msg = "logging.config.dictConfig: " - msg += "handlers found that may interrupt Ansible module " - msg += "execution. " - msg += "Remove these handlers from the logging config file " - msg += "and try again. " bad_handlers.append(handler) if len(bad_handlers) > 0: - msg += f"Handlers: {','.join(bad_handlers)}. " - msg += f"Logging config file: {self.config}." + msg: str = f"Logging config file: {self.config}. " + msg += "logging.config.dictConfig: " + msg += "handlers found that may interrupt Ansible module " + msg += "execution. " + msg += "Remove these handlers from the logging config file " + msg += "and try again. " + msg += f"Bad Handlers: {','.join(bad_handlers)}. " raise ValueError(msg) def commit(self): From 838717dcb5cbed3c6e017ae061c13f19d8f9baa2 Mon Sep 17 00:00:00 2001 From: Allen Robel Date: Fri, 10 Oct 2025 14:35:48 -1000 Subject: [PATCH 2/2] Appease mypy --- lib/nd_python/common/log_v2.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/nd_python/common/log_v2.py b/lib/nd_python/common/log_v2.py index 2161d6a..86a8dd1 100644 --- a/lib/nd_python/common/log_v2.py +++ b/lib/nd_python/common/log_v2.py @@ -290,8 +290,9 @@ def validate_logging_config(self, logging_config: dict) -> None: log.commit() ``` """ + msg: str = "" if len(logging_config.get("handlers", {})) == 0: - msg: str = "logging.config.dictConfig: " + msg = "logging.config.dictConfig: " msg += "No file handlers found. " msg += "Add a file handler to the logging config file " msg += f"and try again: {self.config}" @@ -301,7 +302,7 @@ def validate_logging_config(self, logging_config: dict) -> None: if handler not in self.valid_handlers: bad_handlers.append(handler) if len(bad_handlers) > 0: - msg: str = f"Logging config file: {self.config}. " + msg = f"Logging config file: {self.config}. " msg += "logging.config.dictConfig: " msg += "handlers found that may interrupt Ansible module " msg += "execution. "