From a1307805d9e11a380900272a1070c371da7af075 Mon Sep 17 00:00:00 2001 From: Dan Wolfson Date: Mon, 9 Nov 2026 20:17:01 +0000 Subject: [PATCH 1/3] fix(view): log a report spec refusal at WARNING; correct metric_trend's docstring exec_report_spec logged every ValueError at ERROR. A refusal (AllowlistRefusal, AnalyticFunctionRefused, RoleRefused, CannotRunYet, MicroflowError) is an expected outcome, so it now logs at WARNING; any other ValueError still logs at ERROR. Both are still raised. Tests cover each refusal type and a plain ValueError. metric_trend's docstring said a dotted metric_path still works but is deprecated; it has been refused since 6.2.19. It now says only registered names are accepted. Signed-off-by: Dan Wolfson --- docs/release-notes/6.2.29.md | 9 ++ pyegeria/view/format_set_executor.py | 15 +++- pyegeria/view/overview_metrics.py | 5 +- .../test_report_spec_refusal_log_level.py | 87 +++++++++++++++++++ 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 tests/micro-tests/test_report_spec_refusal_log_level.py diff --git a/docs/release-notes/6.2.29.md b/docs/release-notes/6.2.29.md index 3f340aa4..b625f3bd 100644 --- a/docs/release-notes/6.2.29.md +++ b/docs/release-notes/6.2.29.md @@ -86,3 +86,12 @@ `userAccountStatusProfile` pie charts, and others. - Vega-Lite keys (`...BarGraph`, `...PieGraph`) are not matched. - A column title ending in "Mermaid Graph", "Mermaid Mind Map", "Mermaid Pie Chart" or "Lineage Graph" also counts. + +## Fixed + +- **A report spec refusal logs at WARNING, not ERROR.** `exec_report_spec` logs a refusal + (`AllowlistRefusal`, `AnalyticFunctionRefused`, `RoleRefused`, `CannotRunYet`, `MicroflowError`) at + WARNING, since a refusal is an expected outcome. Any other `ValueError` still logs at ERROR. Both are + still raised. +- **`metric_trend`'s docstring no longer says a dotted `metric_path` still works.** Only registered + names are accepted; a dotted path has been refused (`AnalyticFunctionRefused`) since 6.2.19. diff --git a/pyegeria/view/format_set_executor.py b/pyegeria/view/format_set_executor.py index abfc263e..eb09b748 100644 --- a/pyegeria/view/format_set_executor.py +++ b/pyegeria/view/format_set_executor.py @@ -101,6 +101,17 @@ class AnalyticFunctionRefused(ValueError): pass +def _is_spec_refusal(exc: BaseException) -> bool: + """True when `exc` is a report spec refusal: an expected outcome, not a failure. + + The refusals are the allowlist's (AllowlistRefusal), the analytic-function resolver's + (AnalyticFunctionRefused), a declared input the environment cannot supply (RoleRefused), + and a microflow this pyegeria cannot run or parse (CannotRunYet, MicroflowError). + """ + from pyegeria.view.microflow import AllowlistRefusal, CannotRunYet, MicroflowError # lazy: microflow imports this module + return isinstance(exc, (AllowlistRefusal, AnalyticFunctionRefused, RoleRefused, CannotRunYet, MicroflowError)) + + def analytic_module_prefixes() -> tuple: """The allowed module prefixes: PYEGERIA_ANALYTIC_MODULE_PREFIXES if set, else the defaults.""" raw = os.getenv("PYEGERIA_ANALYTIC_MODULE_PREFIXES", "").strip() @@ -1379,7 +1390,9 @@ def _exec_report_spec_impl( raise except ValueError as e: # Never a silent None (6.2.28): the caller gets the error and its words. - logger.error(f"Report spec '{format_set_name}' ({output_format}) failed: {e}") + # A refusal is expected (WARNING); any other ValueError is a real failure (ERROR). + log = logger.warning if _is_spec_refusal(e) else logger.error + log(f"Report spec '{format_set_name}' ({output_format}) failed: {e}") # Re-raised, as the async path does: a plain-words refusal must not reach the caller as "no result". raise diff --git a/pyegeria/view/overview_metrics.py b/pyegeria/view/overview_metrics.py index caef10aa..9a6b47e7 100644 --- a/pyegeria/view/overview_metrics.py +++ b/pyegeria/view/overview_metrics.py @@ -2058,8 +2058,9 @@ def metric_trend( `metric_path` names the function the way a report spec's `analytic_function` does: a registered analytic function name (e.g. "governed_coverage"). It is resolved through the report-spec resolver - (ISSUE-173), so a caller-supplied value gets the same allowlist check; - a dotted path still works but is deprecated. + (ISSUE-173), so a caller-supplied value gets the same allowlist check. + Only registered names are accepted; a dotted path is refused + (AnalyticFunctionRefused, since 6.2.19). Pass both `mgr` and `ce` regardless of what the target function actually needs -- only the client parameter names it declares (by leading diff --git a/tests/micro-tests/test_report_spec_refusal_log_level.py b/tests/micro-tests/test_report_spec_refusal_log_level.py new file mode 100644 index 00000000..651b13a6 --- /dev/null +++ b/tests/micro-tests/test_report_spec_refusal_log_level.py @@ -0,0 +1,87 @@ +"""exec_report_spec logs a spec refusal at WARNING and any other ValueError at ERROR (6.2.29). + +Both are still raised (6.2.28: never a silent None). Offline: the find method's request raises. +""" +from __future__ import annotations + +import pytest +from loguru import logger + +import pyegeria.view.format_set_executor as fse +from pyegeria.egeria_tech_client import EgeriaTech +from pyegeria.omvs.asset_catalog import AssetCatalog +from pyegeria.view.format_set_executor import AnalyticFunctionRefused, exec_report_spec +from pyegeria.view.microflow import AllowlistRefusal, CannotRunYet, MicroflowError +from pyegeria.view.role_supply import RoleRefused + +pytestmark = pytest.mark.unit + + +@pytest.fixture +def raising_asset_catalog(monkeypatch): + """AssetCatalog with no platform, whose request raises the exception the test sets.""" + box = {} + + def _init(self, view_server, platform_url, user_id=None, user_pwd=None, **_): + self.view_server, self.platform_url, self.user_id = view_server, platform_url, user_id + + async def _request(self, *a, **k): + raise box["exc"] + + real_resolve = fse._resolve_client_and_method + + def _resolve(decl): + cls, method = real_resolve(decl) + return (AssetCatalog, method) if decl == "AssetCatalog.get_asset_graph_by_guid" else (cls, method) + + def _no_egeria_tech(self, *a, **k): + raise AssertionError("the test would have built a real EgeriaTech client") + + monkeypatch.setattr(fse, "_resolve_client_and_method", _resolve) + monkeypatch.setattr(EgeriaTech, "__init__", _no_egeria_tech) + monkeypatch.setattr(AssetCatalog, "__init__", _init) + monkeypatch.setattr(AssetCatalog, "_async_make_request", _request) + monkeypatch.setattr(AssetCatalog, "create_egeria_bearer_token", lambda self, *a, **k: "token") + monkeypatch.setattr(AssetCatalog, "close_session", lambda self: None) + return box + + +@pytest.fixture +def log_records(): + records = [] + sink = logger.add(lambda m: records.append((m.record["level"].name, m.record["message"])), level="DEBUG") + yield records + logger.remove(sink) + + +def _run(): + return exec_report_spec("Asset-Graph", output_format="DICT", params={"guid": "g-1"}, + view_server="qs-view-server", view_url="https://localhost:9443", + user="tester", user_pass="unused") + + +def _failed_lines(records): + return [(level, msg) for level, msg in records if "Report spec 'Asset-Graph' (DICT) failed:" in msg] + + +@pytest.mark.parametrize("exc", [ + AllowlistRefusal("stage 0: not on the allowlist"), + AnalyticFunctionRefused("not a registered name"), + RoleRefused("Routine 'x' cannot run: no reader."), + CannotRunYet("producer/join"), + MicroflowError("not valid JSON"), +], ids=lambda e: type(e).__name__) +def test_a_refusal_logs_at_warning_and_is_raised(raising_asset_catalog, log_records, exc): + raising_asset_catalog["exc"] = exc + with pytest.raises(type(exc)): + _run() + lines = _failed_lines(log_records) + assert [level for level, _ in lines] == ["WARNING"] + assert str(exc) in lines[0][1] + + +def test_an_unexpected_value_error_still_logs_at_error(raising_asset_catalog, log_records): + raising_asset_catalog["exc"] = ValueError("something broke") + with pytest.raises(ValueError, match="something broke"): + _run() + assert [level for level, _ in _failed_lines(log_records)] == ["ERROR"] From 79a70453c72f045f4dbf5dc4e7f8f0a743298756 Mon Sep 17 00:00:00 2001 From: Dan Wolfson Date: Mon, 9 Nov 2026 20:20:30 +0000 Subject: [PATCH 2/3] fix(search): raise SearchRefused for the '*' refusals so they log at WARNING find_elements_by_property_value and find_metadata_elements_with_string refuse '*' with no type (or, for the former, a root type) as a plain ValueError, so exec_report_spec logged them at ERROR. They now raise SearchRefused, a ValueError subclass in pyegeria.core.request_filters, which _is_spec_refusal recognises: they log at WARNING and except ValueError still catches them. Tests: SearchRefused in the refusal cases, an end-to-end Element-DrE-Basic '*' run through exec_report_spec (WARNING, still a ValueError, no request sent), and the existing refusal tests now expect SearchRefused. Signed-off-by: Dan Wolfson --- docs/release-notes/6.2.29.md | 5 +++- pyegeria/core/request_filters.py | 7 ++++++ pyegeria/omvs/classification_explorer.py | 3 ++- pyegeria/omvs/metadata_expert.py | 3 ++- pyegeria/view/format_set_executor.py | 7 ++++-- .../test_report_spec_refusal_log_level.py | 25 +++++++++++++++++++ .../test_search_get_filter_kwargs.py | 5 ++-- 7 files changed, 48 insertions(+), 7 deletions(-) diff --git a/docs/release-notes/6.2.29.md b/docs/release-notes/6.2.29.md index b625f3bd..56df85db 100644 --- a/docs/release-notes/6.2.29.md +++ b/docs/release-notes/6.2.29.md @@ -92,6 +92,9 @@ - **A report spec refusal logs at WARNING, not ERROR.** `exec_report_spec` logs a refusal (`AllowlistRefusal`, `AnalyticFunctionRefused`, `RoleRefused`, `CannotRunYet`, `MicroflowError`) at WARNING, since a refusal is an expected outcome. Any other `ValueError` still logs at ERROR. Both are - still raised. + still raised. The `'*'` refusals in `find_elements_by_property_value` and + `find_metadata_elements_with_string` (no type, or a root type) now raise `SearchRefused`, a `ValueError` + subclass in `pyegeria.core.request_filters`, so they log at WARNING too and `except ValueError` still + catches them. - **`metric_trend`'s docstring no longer says a dotted `metric_path` still works.** Only registered names are accepted; a dotted path has been refused (`AnalyticFunctionRefused`) since 6.2.19. diff --git a/pyegeria/core/request_filters.py b/pyegeria/core/request_filters.py index 45f566d2..c3d555e6 100644 --- a/pyegeria/core/request_filters.py +++ b/pyegeria/core/request_filters.py @@ -61,6 +61,7 @@ "SearchFilters", "FindFilters", "UnknownFilterWarning", + "SearchRefused", "FilterKind", "valid_filter_names", "filter_body_kwargs", @@ -74,6 +75,12 @@ ] +class SearchRefused(ValueError): + """A find_* call refused a search it should not send, such as '*' with no type or a root type + (it would list every element). A ``ValueError``, so ``except ValueError`` still catches it; the + report executor logs it at WARNING, as an expected refusal.""" + + class UnknownFilterWarning(UserWarning): """A find_*/get_* call was given a keyword argument that is not a filter for its request. diff --git a/pyegeria/omvs/classification_explorer.py b/pyegeria/omvs/classification_explorer.py index 81c19531..11d96268 100644 --- a/pyegeria/omvs/classification_explorer.py +++ b/pyegeria/omvs/classification_explorer.py @@ -17,6 +17,7 @@ from pyegeria.core.request_filters import deprecated_names from pyegeria.core.request_filters import GetFilters, ListFilters, SearchFilters from pyegeria.core.request_filters import filter_body_kwargs +from pyegeria.core.request_filters import SearchRefused from pyegeria.core._exceptions import PyegeriaException, PyegeriaInvalidParameterException from pyegeria.core._server_client import ServerClient from pyegeria.core._globals import default_timeout, NO_ELEMENTS_FOUND @@ -3128,7 +3129,7 @@ async def _async_find_elements_by_property_value( if not metadata_element_type or metadata_element_type in _ROOT_TYPES: # A root type is no narrower than no type: listing every element of the repository # ran the quickstart platform out of heap (2026-11-09), so it is refused like '*'. - raise ValueError("find_elements_by_property_value: give a search string or a narrower type " + raise SearchRefused("find_elements_by_property_value: give a search string or a narrower type " "('*' with no metadata_element_type, or with " f"{'/'.join(sorted(_ROOT_TYPES))}, would list every element)") # Never fetch a whole type in one call: one page of at most STAR_PAGE_MAX, paged by start_from. diff --git a/pyegeria/omvs/metadata_expert.py b/pyegeria/omvs/metadata_expert.py index 31f8f1ea..69598229 100644 --- a/pyegeria/omvs/metadata_expert.py +++ b/pyegeria/omvs/metadata_expert.py @@ -13,6 +13,7 @@ from pyegeria.core.request_filters import deprecated_names from pyegeria.core.request_filters import FindFilters from pyegeria.core.request_filters import filter_body_kwargs +from pyegeria.core.request_filters import SearchRefused from pyegeria.models import (NewOpenMetadataElementRequestBody, TemplateRequestBody, UpdatePropertiesRequestBody, MetadataSourceRequestBody, ReIdentifyRequestBody, ReTypeRequestBody, ReHomeRequestBody, @@ -2266,7 +2267,7 @@ async def _async_find_metadata_elements_with_string(self, search_string: str = " if search_string in (None, "", "*") and body is None and not ( metadata_element_type or metadata_element_subtypes or include_only_classified_elements): # Egeria refuses this with "searchString is null" (OMAG-COMMON-400-022); say why in plain words. - raise ValueError("find_metadata_elements_with_string: give a search string or a type " + raise SearchRefused("find_metadata_elements_with_string: give a search string or a type " "(metadata_element_type, metadata_element_subtypes or " "include_only_classified_elements); '*' alone is not a search") url = ( diff --git a/pyegeria/view/format_set_executor.py b/pyegeria/view/format_set_executor.py index eb09b748..aae2e33f 100644 --- a/pyegeria/view/format_set_executor.py +++ b/pyegeria/view/format_set_executor.py @@ -106,10 +106,13 @@ def _is_spec_refusal(exc: BaseException) -> bool: The refusals are the allowlist's (AllowlistRefusal), the analytic-function resolver's (AnalyticFunctionRefused), a declared input the environment cannot supply (RoleRefused), - and a microflow this pyegeria cannot run or parse (CannotRunYet, MicroflowError). + a microflow this pyegeria cannot run or parse (CannotRunYet, MicroflowError), and a search a + find method refuses to send (SearchRefused: '*' with no type or a root type). """ from pyegeria.view.microflow import AllowlistRefusal, CannotRunYet, MicroflowError # lazy: microflow imports this module - return isinstance(exc, (AllowlistRefusal, AnalyticFunctionRefused, RoleRefused, CannotRunYet, MicroflowError)) + from pyegeria.core.request_filters import SearchRefused + return isinstance(exc, (AllowlistRefusal, AnalyticFunctionRefused, RoleRefused, CannotRunYet, MicroflowError, + SearchRefused)) def analytic_module_prefixes() -> tuple: diff --git a/tests/micro-tests/test_report_spec_refusal_log_level.py b/tests/micro-tests/test_report_spec_refusal_log_level.py index 651b13a6..27b2df45 100644 --- a/tests/micro-tests/test_report_spec_refusal_log_level.py +++ b/tests/micro-tests/test_report_spec_refusal_log_level.py @@ -13,6 +13,7 @@ from pyegeria.view.format_set_executor import AnalyticFunctionRefused, exec_report_spec from pyegeria.view.microflow import AllowlistRefusal, CannotRunYet, MicroflowError from pyegeria.view.role_supply import RoleRefused +from pyegeria.core.request_filters import SearchRefused pytestmark = pytest.mark.unit @@ -70,6 +71,7 @@ def _failed_lines(records): RoleRefused("Routine 'x' cannot run: no reader."), CannotRunYet("producer/join"), MicroflowError("not valid JSON"), + SearchRefused("give a search string or a narrower type"), ], ids=lambda e: type(e).__name__) def test_a_refusal_logs_at_warning_and_is_raised(raising_asset_catalog, log_records, exc): raising_asset_catalog["exc"] = exc @@ -85,3 +87,26 @@ def test_an_unexpected_value_error_still_logs_at_error(raising_asset_catalog, lo with pytest.raises(ValueError, match="something broke"): _run() assert [level for level, _ in _failed_lines(log_records)] == ["ERROR"] + + +def test_search_refused_is_a_value_error(): + assert issubclass(SearchRefused, ValueError) + + +def test_star_on_a_root_type_logs_at_warning_through_exec_report_spec(monkeypatch, log_records): + """End to end: Element-DrE-Basic searches OpenMetadataRoot; '*' is refused before any request.""" + from pyegeria.omvs.classification_explorer import ClassificationExplorer + + async def _no_request(self, *a, **k): + raise AssertionError("the refusal should come before any request") + + monkeypatch.setattr(ClassificationExplorer, "_async_make_request", _no_request) + monkeypatch.setattr(EgeriaTech, "close_session", lambda self: None, raising=False) + with pytest.raises(ValueError) as exc: + exec_report_spec("Element-DrE-Basic", output_format="DICT", params={"search_string": "*"}, + view_server="qs-view-server", view_url="https://localhost:9443", + user="tester", user_pass="unused", token="offline-token") + assert isinstance(exc.value, SearchRefused) + assert "give a search string or a narrower type" in str(exc.value) + lines = [(level, msg) for level, msg in log_records if "Report spec 'Element-DrE-Basic' (DICT) failed:" in msg] + assert [level for level, _ in lines] == ["WARNING"] diff --git a/tests/micro-tests/test_search_get_filter_kwargs.py b/tests/micro-tests/test_search_get_filter_kwargs.py index 7abe1e25..5c1ff53d 100644 --- a/tests/micro-tests/test_search_get_filter_kwargs.py +++ b/tests/micro-tests/test_search_get_filter_kwargs.py @@ -406,15 +406,16 @@ def test_every_generic_search_spec_names_a_type(): def test_untyped_star_is_refused_with_words(explorer, monkeypatch): + from pyegeria.core.request_filters import SearchRefused from pyegeria.omvs.metadata_expert import MetadataExpert - with pytest.raises(ValueError, match="give a search string or a"): + with pytest.raises(SearchRefused, match="give a search string or a"): explorer.find_elements_by_property_value("*", ["displayName"]) assert not explorer.sent monkeypatch.setattr(MetadataExpert, "check_connection", lambda self: "test") expert = MetadataExpert("view-server", "https://egeria.example:9443", "user", "pwd") - with pytest.raises(ValueError, match="give a search string or a type"): + with pytest.raises(SearchRefused, match="give a search string or a type"): expert.find_metadata_elements_with_string("*") From 3896e4fb9d82f2fab049ac07ceb43e10c5dd4f39 Mon Sep 17 00:00:00 2001 From: Dan Wolfson Date: Mon, 9 Nov 2026 20:28:37 +0000 Subject: [PATCH 3/3] docs(release-notes): say which refusals reach the WARNING log; stub raises SearchRefused The WARNING branch wraps only the find call, so the release note now says a refusal that reaches exec_report_spec's failure log (today the '*' search refusals, SearchRefused) logs at WARNING, and that the analytic and role refusals are raised before that log. The executor test stub for the '*' refusal raises SearchRefused, as the real find methods do. Signed-off-by: Dan Wolfson --- docs/release-notes/6.2.29.md | 13 ++++++------- tests/micro-tests/test_search_get_filter_kwargs.py | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/release-notes/6.2.29.md b/docs/release-notes/6.2.29.md index 56df85db..036396ee 100644 --- a/docs/release-notes/6.2.29.md +++ b/docs/release-notes/6.2.29.md @@ -89,12 +89,11 @@ ## Fixed -- **A report spec refusal logs at WARNING, not ERROR.** `exec_report_spec` logs a refusal - (`AllowlistRefusal`, `AnalyticFunctionRefused`, `RoleRefused`, `CannotRunYet`, `MicroflowError`) at - WARNING, since a refusal is an expected outcome. Any other `ValueError` still logs at ERROR. Both are - still raised. The `'*'` refusals in `find_elements_by_property_value` and - `find_metadata_elements_with_string` (no type, or a root type) now raise `SearchRefused`, a `ValueError` - subclass in `pyegeria.core.request_filters`, so they log at WARNING too and `except ValueError` still - catches them. +- **A report spec refusal logs at WARNING, not ERROR.** A refusal that reaches `exec_report_spec`'s + failure log (today the `'*'` search refusals, now `SearchRefused`) logs at WARNING; any other + `ValueError` still logs at ERROR; both are raised. The analytic and role refusals are raised before + that log. `SearchRefused` is raised by `find_elements_by_property_value` and + `find_metadata_elements_with_string` for `'*'` with no type (or a root type); it is a `ValueError` + subclass in `pyegeria.core.request_filters`, so `except ValueError` still catches it. - **`metric_trend`'s docstring no longer says a dotted `metric_path` still works.** Only registered names are accepted; a dotted path has been refused (`AnalyticFunctionRefused`) since 6.2.19. diff --git a/tests/micro-tests/test_search_get_filter_kwargs.py b/tests/micro-tests/test_search_get_filter_kwargs.py index 5c1ff53d..eb27ac8b 100644 --- a/tests/micro-tests/test_search_get_filter_kwargs.py +++ b/tests/micro-tests/test_search_get_filter_kwargs.py @@ -558,7 +558,8 @@ def close_session(self): pass def find_things(self, search_string="*", **kwargs): - raise ValueError("give a search string or a narrower type") + from pyegeria.core.request_filters import SearchRefused + raise SearchRefused("give a search string or a narrower type") fmt = {"action": {"function": "X.find_things", "required_params": ["search_string"], "spec_params": {}}} monkeypatch.setattr(fse, "select_report_spec", lambda name, kind: fmt)