From 28fbfa5e26f7770209b61a60faf573d21be8c526 Mon Sep 17 00:00:00 2001 From: Dan Wolfson Date: Sat, 7 Nov 2026 21:31:50 +0000 Subject: [PATCH] fix(metadata-expert): pass report_spec through find methods The four MetadataExpert find methods (find_metadata_elements_with_string, find_elements_for_anchor, find_elements_in_anchor_domain, find_elements_in_anchor_scope) hardcoded report_spec=None in their _async_find_request call while also forwarding **kwargs. exec_report_spec always adds report_spec to the call, so every report spec backed by one of them (40 registered specs, e.g. Report-DrE-Basic) failed with "got multiple values for keyword argument 'report_spec'". Each method now takes report_spec explicitly and passes it on, so the spec's own columns are used for non-JSON output. The new micro-test runs every registered spec naming find_metadata_elements_with_string through exec_report_spec, plus each of the four sync methods directly, against the real client with only _async_make_request faked. Signed-off-by: Dan Wolfson --- pyegeria/omvs/metadata_expert.py | 12 ++- .../test_metadata_expert_report_spec_kwarg.py | 90 +++++++++++++++++++ 2 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 tests/micro-tests/test_metadata_expert_report_spec_kwarg.py diff --git a/pyegeria/omvs/metadata_expert.py b/pyegeria/omvs/metadata_expert.py index a651cee6..1236fe15 100644 --- a/pyegeria/omvs/metadata_expert.py +++ b/pyegeria/omvs/metadata_expert.py @@ -2189,6 +2189,7 @@ async def _async_find_metadata_elements_with_string(self, search_string: str = " sequencing_property: str = "qualifiedName", start_from: int = 0, page_size: int = 0, output_format: str = "JSON", + report_spec: Optional[str | dict] = None, body: SearchStringRequestBody | dict = None, **kwargs) -> list | str: """ Searches for metadata elements based on a string pattern with a comprehensive filtering @@ -2265,7 +2266,7 @@ async def _async_find_metadata_elements_with_string(self, search_string: str = " limit_results_by_status=limit_results_by_status, sequencing_order=sequencing_order, sequencing_property=sequencing_property, output_format=output_format, - report_spec=None, start_from=start_from, page_size=page_size, + report_spec=report_spec, start_from=start_from, page_size=page_size, body=body, **kwargs) return response @@ -2371,6 +2372,7 @@ async def _async_find_elements_for_anchor(self, guid: Optional[str] = None, sear sequencing_property: str = "qualifiedName", start_from: int = 0, page_size: int = 0, output_format: str = "JSON", + report_spec: Optional[str | dict] = None, body: SearchStringRequestBody | dict = None, **kwargs) -> list | str: """ Return a list of elements with the requested search string in their (display, resource) name, qualified name, @@ -2448,7 +2450,7 @@ async def _async_find_elements_for_anchor(self, guid: Optional[str] = None, sear limit_results_by_status=limit_results_by_status, sequencing_order=sequencing_order, sequencing_property=sequencing_property, output_format=output_format, - report_spec=None, start_from=start_from, page_size=page_size, + report_spec=report_spec, start_from=start_from, page_size=page_size, body=body, **kwargs) return response @@ -2552,6 +2554,7 @@ async def _async_find_elements_in_anchor_domain(self, search_string: str = "*", sequencing_property: str = "qualifiedName", start_from: int = 0, page_size: int = 0, output_format: str = "JSON", + report_spec: Optional[str | dict] = None, body: SearchStringRequestBody | dict = None, **kwargs) -> list | str: """ Return a list of elements with the requested search string in their (display, resource) name, qualified name, @@ -2629,7 +2632,7 @@ async def _async_find_elements_in_anchor_domain(self, search_string: str = "*", limit_results_by_status=limit_results_by_status, sequencing_order=sequencing_order, sequencing_property=sequencing_property, output_format=output_format, - report_spec=None, start_from=start_from, page_size=page_size, + report_spec=report_spec, start_from=start_from, page_size=page_size, body=body, **kwargs) return response @@ -2732,6 +2735,7 @@ async def _async_find_elements_in_anchor_scope(self, guid: Optional[str] = None, sequencing_property: str = "qualifiedName", start_from: int = 0, page_size: int = 0, output_format: str = "JSON", + report_spec: Optional[str | dict] = None, body: SearchStringRequestBody | dict = None, **kwargs) -> list | str: """ Return a list of elements with the requested search string in their (display, resource) name, qualified name, @@ -2813,7 +2817,7 @@ async def _async_find_elements_in_anchor_scope(self, guid: Optional[str] = None, limit_results_by_status=limit_results_by_status, sequencing_order=sequencing_order, sequencing_property=sequencing_property, output_format=output_format, - report_spec=None, start_from=start_from, page_size=page_size, + report_spec=report_spec, start_from=start_from, page_size=page_size, body=body, **kwargs) return response diff --git a/tests/micro-tests/test_metadata_expert_report_spec_kwarg.py b/tests/micro-tests/test_metadata_expert_report_spec_kwarg.py new file mode 100644 index 00000000..cb228c4c --- /dev/null +++ b/tests/micro-tests/test_metadata_expert_report_spec_kwarg.py @@ -0,0 +1,90 @@ +"""MetadataExpert find methods under exec_report_spec. + +exec_report_spec always adds `report_spec=` to the call. The +MetadataExpert find methods hardcoded `report_spec=None` in their +`_async_find_request(...)` call while also forwarding `**kwargs`, so every +report spec backed by one of them (e.g. `Report-DrE-Basic`, `Dashboards`) +failed with "got multiple values for keyword argument 'report_spec'". These +tests run the real client class with only the HTTP transport faked. +""" +import pytest + +import pyegeria.view.format_set_executor as fse +from pyegeria.core._server_client import ServerClient +from pyegeria.omvs.metadata_expert import MetadataExpert +from pyegeria.view.base_report_formats import get_report_registry + +_ELEMENT = { + "elementHeader": { + "guid": "g1", + "type": {"typeName": "Referenceable"}, + "origin": {"homeMetadataCollectionId": "mc1", "homeMetadataCollectionName": "mc"}, + "versions": {"createdBy": "u", "createTime": "2026-11-07T00:00:00Z", "version": 1}, + "status": "ACTIVE", + "class": "ElementHeader", + }, + "properties": {"qualifiedName": "Referenceable::x", "displayName": "x"}, +} + + +class _FakeResponse: + def json(self): + return {"elements": [_ELEMENT]} + + +@pytest.fixture(autouse=True) +def _offline(monkeypatch): + calls = [] + + async def fake_make_request(self, request_type, endpoint, payload=None, *args, **kwargs): + calls.append((request_type, endpoint, payload)) + return _FakeResponse() + + monkeypatch.setattr(ServerClient, "_async_make_request", fake_make_request) + monkeypatch.setattr(ServerClient, "create_egeria_bearer_token", lambda self, *a, **k: "token") + monkeypatch.setattr(ServerClient, "set_bearer_token", lambda self, token: None) + monkeypatch.setattr(ServerClient, "check_connection", lambda self: "ok", raising=False) + return calls + + +def _specs_using(method: str) -> list[str]: + names = [] + for name, fs in get_report_registry().items(): + action = getattr(fs, "action", None) + if action is not None and getattr(action, "function", None) == f"MetadataExpert.{method}": + names.append(name) + return sorted(names) + + +_WITH_STRING_SPECS = _specs_using("find_metadata_elements_with_string") + + +def test_known_failing_spec_is_covered(): + # Reproduced live 2026-11-07. Specs added later on the same function + # (e.g. Dashboards) are picked up by the registry scan below. + assert "Report-DrE-Basic" in _WITH_STRING_SPECS + + +@pytest.mark.parametrize("spec_name", _WITH_STRING_SPECS) +def test_exec_report_spec_runs(spec_name, _offline): + result = fse.exec_report_spec(spec_name, output_format="DICT", params={"search_string": "*"}, + view_server="v", view_url="https://x", user="u", user_pass="p") + assert result["kind"] != "unknown", result + assert "multiple values" not in str(result) + assert _offline, "expected one request to Egeria" + assert _offline[0][1].endswith("/metadata-elements/by-search-string") + + +@pytest.mark.parametrize("method, args", [ + ("find_metadata_elements_with_string", {}), + ("find_elements_for_anchor", {"guid": "a1"}), + ("find_elements_in_anchor_domain", {"anchor_domain": "Glossary"}), + ("find_elements_in_anchor_scope", {"guid": "a1"}), +]) +def test_find_methods_accept_report_spec(method, args, _offline): + client = MetadataExpert("v", "https://x", "u", "p") + result = getattr(client, method)(search_string="*", output_format="DICT", + report_spec="Referenceable", **args) + assert isinstance(result, list), result + # report_spec is a client-side rendering option and must not reach the request body + assert "report_spec" not in _offline[0][2] and "reportSpec" not in _offline[0][2]