diff --git a/pyproject.toml b/pyproject.toml index c42db1a9e..3a5b25455 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ description = "ValidMind Library" license = "Commercial License" name = "validmind" readme = "README.pypi.md" -version = "2.8.9" +version = "2.8.10" [tool.poetry.dependencies] python = ">=3.8.1,<3.12" diff --git a/validmind/__version__.py b/validmind/__version__.py index e71de367e..71322b8ca 100644 --- a/validmind/__version__.py +++ b/validmind/__version__.py @@ -1 +1 @@ -__version__ = "2.8.9" +__version__ = "2.8.10" diff --git a/validmind/vm_models/result/result.py b/validmind/vm_models/result/result.py index 82da5edeb..382a24996 100644 --- a/validmind/vm_models/result/result.py +++ b/validmind/vm_models/result/result.py @@ -171,6 +171,7 @@ class TestResult(Result): metadata: Optional[Dict[str, Any]] = None _was_description_generated: bool = False _unsafe: bool = False + _client_config_cache: Optional[Any] = None def __post_init__(self): if self.ref_id is None: @@ -329,13 +330,50 @@ def to_widget(self): return VBox(widgets) + @classmethod + def _get_client_config(cls): + """Get the client config, loading it if not cached""" + if cls._client_config_cache is None: + api_client.reload() + cls._client_config_cache = api_client.client_config + + if cls._client_config_cache is None: + raise ValueError( + "Failed to load client config: api_client.client_config is None" + ) + + if not hasattr(cls._client_config_cache, "documentation_template"): + raise ValueError( + "Invalid client config: missing documentation_template" + ) + + return cls._client_config_cache + + def check_result_id_exist(self): + """Check if the result_id exists in any test block across all sections""" + client_config = self._get_client_config() + + # Iterate through all sections + for section in client_config.documentation_template["sections"]: + blocks = section.get("contents", []) + # Check each block in the section + for block in blocks: + if ( + block.get("content_type") == "test" + and block.get("content_id") == self.result_id + ): + return + + logger.info( + f"Test driven block with result_id {self.result_id} does not exist in model's document" + ) + def _validate_section_id_for_block( self, section_id: str, position: Union[int, None] = None ): """Validate the section_id exits on the template before logging""" - api_client.reload() + client_config = self._get_client_config() found = False - client_config = api_client.client_config for section in client_config.documentation_template["sections"]: if section["id"] == section_id: @@ -440,6 +478,9 @@ def log(self, section_id: str = None, position: int = None, unsafe: bool = False unsafe (bool): If True, log the result even if it contains sensitive data i.e. raw data from input datasets """ + + self.check_result_id_exist() + if not unsafe: for table in self.tables or []: check_for_sensitive_data(table.data, self._get_flat_inputs())