From a037c7798ed34a122dbb0d6a71eeef1a57279ffa Mon Sep 17 00:00:00 2001 From: leavesster <11785335+leavesster@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:12:15 +0800 Subject: [PATCH] fix: prevent oomol_llm_env property side effect on repeated access Property was calling send_warning on every access, which violates property semantics. Now only warns once on first access using a cached flag. --- oocana/oocana/context.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/oocana/oocana/context.py b/oocana/oocana/context.py index 40f4cac..2820b10 100644 --- a/oocana/oocana/context.py +++ b/oocana/oocana/context.py @@ -185,6 +185,7 @@ class Context: __package_name: str | None = None _logger: Optional[logging.Logger] = None __pkg_data_dir: str + __oomol_llm_env_warned: bool = False # TODO: remove the pkg_dir parameter, use pkg_data_dir instead. def __init__( @@ -310,11 +311,14 @@ def oomol_llm_env(self) -> OOMOL_LLM_ENV: "models": os.getenv("OOMOL_LLM_MODELS", "").split(","), } - for key, value in oomol_llm_env.items(): - if value == "" or value == []: - self.send_warning( - f"OOMOL_LLM_ENV variable {key} is ({value}), this may cause some features not working properly." - ) + # Only warn once on first access to avoid repeated side effects + if not self.__oomol_llm_env_warned: + self.__oomol_llm_env_warned = True + for key, value in oomol_llm_env.items(): + if value == "" or value == []: + self.send_warning( + f"OOMOL_LLM_ENV variable {key} is ({value}), this may cause some features not working properly." + ) return oomol_llm_env