diff --git a/PYEGERIA_ISSUES.md b/PYEGERIA_ISSUES.md index 4dca53e6..44996ba9 100644 --- a/PYEGERIA_ISSUES.md +++ b/PYEGERIA_ISSUES.md @@ -172,6 +172,7 @@ re-test candidates moved into *Awaiting re-test* below the open sections. create-from-template) and 7 (`viewElementGUID`) are still open. **Open pyegeria items** +- ISSUE-185: get_collection_members ignored start_from/page_size, so a paged read repeated page 1 ("≥60" for 3) (fixed for 6.2.36) - ISSUE-184: a Smart Collection was recognised by the Portal's `smartCollection` flag, not by Egeria's catalog target (fixed for 6.2.35) - ISSUE-183: deleting a SavedQuery left its SmartQuery links, and pyegeria had no delete that detached them (fixed for 6.2.35) - ISSUE-182: an element hidden by zone security (403-020) was reported as AUTHORIZATION_ERROR_401 (fixed in 6.2.34) @@ -197,6 +198,18 @@ into the entry now, so it isn't rediscovered from scratch later. --- +### ISSUE-185: get_collection_members ignored start_from and page_size + +**Layer:** pyegeria · **Severity:** HIGH: a false figure on a live tile · **Status:** fixed 2026-11-11 on branch `fix/collection-members-paging`, targets 6.2.36 · **Found:** 2026-11-11, the Architect's live Route B read-back on laz: (0,50), (3,50), (50,50), (0,2) and (2,2) all returned the same 3 members. + +**What:** `_async_get_collection_members` takes `start_from` and `page_size` as its own parameters, so they are not in `**kwargs`, and it never passed them to `_async_get_results_body_request`: every call read the first page. `saved_query._read_pages` pages until an empty page, so it re-read the same 3 members until `max_pages` and reported `capped`, `atLeast` 60. Separately, both request helpers dropped paging arguments whenever a caller passed a body. + +**Done:** the method passes its paging on; `_with_paging` adds a call's paging to a body that sets none; `_read_pages` counts distinct elements and stops, not capped, with "paging did not advance" when a page brings nothing new; the three unbounded paging loops (`dashboards._dashboard_elements`, the dashboard sheet writer's `_related` and Report-name read) stop the same way. + +**Audit:** of 101 list methods taking `start_from`/`page_size`, this was the only one not forwarding them. `egeria_folders` read each folder in one unpaged call (the Architect's LD-3 note N2); it now pages every folder to its end, deduplicated, and a folder over 10,000 members is reported as not fully read (`FolderTooLarge`). Still single-call member reads (the server's default page): `base_report_formats` (report-type members) and `commands/cat/get_collection_tree.py`; worth paging if those can exceed the default page. + +Tests: `tests/micro-tests/test_collection_members_paging.py`. + ### ISSUE-184: a Smart Collection was recognised by a flag, not by Egeria's record **Layer:** pyegeria · **Severity:** medium: a cached answer could be served as "kept current by Egeria" when it was not, or refused when it was · **Status:** fixed 2026-11-11 on branch `feat/smart-collection-catalog-target`, targets 6.2.35 · **Found:** backlog, from the Smart Collections design (Egeria #9200, 0725). diff --git a/docs/release-notes/6.2.36.md b/docs/release-notes/6.2.36.md new file mode 100644 index 00000000..93742f61 --- /dev/null +++ b/docs/release-notes/6.2.36.md @@ -0,0 +1,45 @@ +# pyegeria 6.2.36 + +pyegeria 6.2.36 fixes one bug with a visible symptom: +- `get_collection_members` pages: it used to read the first page whatever `start_from` and `page_size` said, so a + saved query's tile read "at least 60" for a Results Set of 3 (ISSUE-185). + +## Fixed + +- **`get_collection_members` honours `start_from` and `page_size`** (ISSUE-185). They are the method's own + parameters, so they never reached the request and every call read the first page. A reader paging until an empty + page (`saved_query`) therefore re-read the same members until its bound and reported a false lower bound: a + 3-member Results Set read as "≥60" on the Portal and in EA. +- **Paging given as arguments is no longer dropped with a body.** Both request helpers (results-body and name) + add the call's `start_from`/`page_size` to a caller's body when the body sets no paging of its own; a body's own + paging still wins. + **Behaviour change (Architect N1):** with `body=` and no paging in the body, the method's `page_size` default now + applies. Until 6.2.35 such a call got Egeria's default page. Nineteen methods have a non-zero default and are + affected: `ClassificationExplorer.get_elements` (10); `ActorManager.get_user_identities_by_name`, + `get_contribution_records_by_name`, `get_contact_details_by_name`, `get_perspectives_by_name`, + `get_skills_by_name`, `CollectionManager.get_collections_by_name`, `MyProfile.get_my_actors`, + `get_my_user_identities`, `get_my_roles`, `get_my_resources`, `RuntimeManager.get_elements_by_category`, + `SchemaMaker.get_schema_types_by_name` and `get_schema_attributes_by_name` (100); + `RuntimeManager.get_platforms_by_type`, `get_platform_templates_by_type`, `get_servers_by_name`, + `SolutionArchitect.get_design_patterns_by_name` and `get_concept_model_elements_by_name` (`max_paging_size`, 500 + by default). A caller relying on Egeria's default page with a body should put `pageSize` in the body, or pass + `page_size` explicitly. The Portal's and Trellis' callers are not affected. +- **A repeated page is never a count** (`saved_query`). Its reader counts distinct elements, and a page that brings + nothing new stops the read: the answer is the distinct elements read, not capped, with "paging did not advance" + in its `note`. A read that genuinely reaches its bound is still capped. +- **The folder walk reads every folder to its end** (`egeria_folders`, used by the report-spec cache, the consumer + indexes and the dashboard folder listing). Each folder was one unpaged read, so a folder over the server's + default page was silently truncated. Each is now paged until an empty page and deduplicated by GUID; a folder + over the walk's bound (10,000 members) is reported as not fully read, never as a short one. +- **No paging loop can run forever.** The Dashboard listing (`dashboards`) and the dashboard sheet writer's two + related-element and Report-name reads paged with no bound; each now stops, with a warning, when a page brings + nothing new. + +## Audit + +Of 101 list methods that take `start_from`/`page_size`, `get_collection_members` was the only one that did not +pass them on. The other paged-to-empty loops (`overview_metrics`, `md_processing`'s processors, +`base_report_formats`) are bounded. The folder walk (`egeria_folders`) read +each folder in one unpaged call; it now pages (above). Two callers still read members in one call without paging, +so they see the server's default page: `base_report_formats` (report-type members) and +`commands/cat/get_collection_tree.py`. They are listed in ISSUE-185 for a later look. diff --git a/md_processing/v2/dashboard_sheet.py b/md_processing/v2/dashboard_sheet.py index 69369627..d65622d6 100644 --- a/md_processing/v2/dashboard_sheet.py +++ b/md_processing/v2/dashboard_sheet.py @@ -326,7 +326,11 @@ async def _related(self, guid: Optional[str], relationship: str, start_at_end: i items = [e for e in page if isinstance(e, dict) and e.get("elementHeader")] if isinstance(page, list) else [] if not items: return out - out.extend(items) + known = {self._guid(e) for e in out} + if all(self._guid(e) in known for e in items): # paging did not advance; it would never end (6.2.36) + logger.warning(f"dashboard sheet: paging of {relationship} for {guid} did not advance at {start}") + return out + out.extend(e for e in items if self._guid(e) not in known) start += len(items) @staticmethod @@ -509,6 +513,7 @@ async def _resolve_report(self, report_name: str) -> Optional[str]: when the name is shared with an element of another type -- seen live 2026-11-09 for 'Term Definition Completeness' and 'Governance Classification Coverage', both real Reports.""" matches: List[str] = [] + seen: set = set() start = 0 while True: try: @@ -520,6 +525,11 @@ async def _resolve_report(self, report_name: str) -> Optional[str]: items = [e for e in page if isinstance(e, dict) and e.get("elementHeader")] if isinstance(page, list) else [] if not items: break + if all(self._guid(e) in seen for e in items): # paging did not advance; it would never end (6.2.36) + logger.warning(f"dashboard sheet: paging of Reports named {report_name!r} did not advance at {start}") + break + items = [e for e in items if self._guid(e) not in seen] + seen.update(self._guid(e) for e in items) matches += [self._guid(e) for e in items if (e.get("properties") or {}).get("displayName") == report_name and self._type(e) == "Report"] diff --git a/pyegeria/core/_server_client.py b/pyegeria/core/_server_client.py index 681f1b75..6a8ca59a 100644 --- a/pyegeria/core/_server_client.py +++ b/pyegeria/core/_server_client.py @@ -120,6 +120,19 @@ # Exceptions + +def _with_paging(body: dict, start_from: int, page_size: int) -> dict: + """A caller's body, with the call's own paging when the body sets none (6.2.36). Paging given as arguments was + dropped whenever a body was passed, so a loop that pages with start_from/page_size and a body re-read page 1.""" + if not (start_from or page_size): + return body + out = dict(body) + if start_from and not ({"startFrom", "start_from"} & body.keys()): + out["startFrom"] = start_from + if page_size and not ({"pageSize", "page_size"} & body.keys()): + out["pageSize"] = page_size + return out + class ServerClient(BaseServerClient): """ An abstract class used to establish connectivity for an Egeria Client @@ -6620,7 +6633,8 @@ async def _async_get_name_request(self, url: str, _type: str, _gen_output: Calla if isinstance(body, FilterRequestBody): validated_body = body elif isinstance(body, dict): - validated_body = self._validate_body(self._filter_request_adapter.validate_python, body) + validated_body = self._validate_body(self._filter_request_adapter.validate_python, + _with_paging(body, start_from, page_size)) else: filter_string = None if filter_string == "*" else filter_string classification_names = None if classification_names == [] else classification_names @@ -7232,7 +7246,8 @@ async def _async_get_results_body_request(self, url: str, _type: str, _gen_outpu if isinstance(body, ResultsRequestBody): validated_body = body elif isinstance(body, dict): - validated_body = self._validate_body(self._results_request_adapter.validate_python, body) + validated_body = self._validate_body(self._results_request_adapter.validate_python, + _with_paging(body, start_from, page_size)) else: body = { "class": "ResultsRequestBody", diff --git a/pyegeria/omvs/collection_manager.py b/pyegeria/omvs/collection_manager.py index 888fce4d..d5567c28 100644 --- a/pyegeria/omvs/collection_manager.py +++ b/pyegeria/omvs/collection_manager.py @@ -1298,8 +1298,12 @@ async def _async_get_collection_members(self, collection_guid: Optional[str] = N # are never guaranteed to share the collection's own type (e.g. a # WorkItemList's members are Projects), so the default request body must # not filter results by it. + # start_from / page_size are this method's own parameters, so they are not in **kwargs: until 6.2.36 they were + # never passed on, every call read the first page, and a reader paging to an empty page re-read the same + # members until its bound (a 3-member Results Set read as "at least 60", ISSUE-185). response = await self._async_get_results_body_request(url, _type="Collection", _gen_output=self._generate_collection_output, + start_from=start_from, page_size=page_size, output_format=output_format, report_spec=report_spec, body=body, filter_results_by_type=False, **kwargs) diff --git a/pyegeria/view/dashboards.py b/pyegeria/view/dashboards.py index fe1e0cd6..d584cc72 100644 --- a/pyegeria/view/dashboards.py +++ b/pyegeria/view/dashboards.py @@ -280,6 +280,7 @@ async def _dashboard_elements(client: Any) -> List[Dict[str, Any]]: small type; only an empty page ends the read) and filtered here: a starts-with search on qualifiedName took 21 s on the live platform with no Dashboards at all, the type read 2.8 s.""" out: List[Dict[str, Any]] = [] + seen: set = set() start = 0 while True: page = await client.classification_manager._async_get_elements( @@ -287,6 +288,12 @@ async def _dashboard_elements(client: Any) -> List[Dict[str, Any]]: items = [e for e in page if isinstance(e, dict) and e.get("elementHeader")] if isinstance(page, list) else [] if not items: return out + fresh = [e for e in items if (e.get("elementHeader") or {}).get("guid") not in seen] + if not fresh: # a page of elements already read: paging did not advance, and would never end (6.2.36) + logger.warning(f"dashboards: paging did not advance at position {start}; stopped with {len(seen)} read") + return out + seen.update((e.get("elementHeader") or {}).get("guid") for e in fresh) + items = fresh out.extend(e for e in items if ((e.get("properties") or {}).get("qualifiedName") or "").startswith(DASHBOARD_QN_PREFIX)) start += len(items) diff --git a/pyegeria/view/egeria_folders.py b/pyegeria/view/egeria_folders.py index 5ed28f0a..a45d9f9a 100644 --- a/pyegeria/view/egeria_folders.py +++ b/pyegeria/view/egeria_folders.py @@ -84,6 +84,35 @@ def _call(fn, *args, **kwargs): return _elements(result) +MEMBERS_PAGE = 100 +MEMBERS_MAX_PAGES = 100 + + +class FolderTooLarge(RuntimeError): + """A folder has more members than one walk reads; reported as a folder not fully read, never as a short one.""" + + +def _members(client, collection_guid: str) -> List[Dict[str, Any]]: + """Every member of a collection, each once: paged until Egeria returns an EMPTY page (a short page is not the + last), deduplicated by GUID, and stopped when a page brings nothing new (a server that ignores paging returns the + same page again; 6.2.36). It used to be one unpaged call, so a folder over the server's default page was + silently truncated (Architect, LD-3 note N2). More than MEMBERS_MAX_PAGES pages raises FolderTooLarge.""" + out: List[Dict[str, Any]] = [] + seen: set = set() + for page_no in range(MEMBERS_MAX_PAGES): + page = _call(client.get_collection_members, collection_guid=collection_guid, + start_from=page_no * MEMBERS_PAGE, page_size=MEMBERS_PAGE, output_format="JSON") + if not page: + return out + fresh = [m for m in page if (_guid(m) or id(m)) not in seen] + if not fresh: + return out + for m in fresh: + seen.add(_guid(m) or id(m)) + out.extend(fresh) + raise FolderTooLarge(f"more than {MEMBERS_MAX_PAGES * MEMBERS_PAGE} members; not read to the end") + + def client_identity(client) -> str: return str(getattr(client, "user_id", "") or "?") @@ -170,11 +199,10 @@ def walk_folder(client, folder: Dict[str, Any], *, recursive: bool, consumer_pre while queue: current, depth, path = queue.pop(0) if depth == 0: - listed = _call(client.get_collection_members, collection_guid=_guid(current), output_format="JSON") + listed = _members(client, _guid(current)) else: try: - listed = _call(client.get_collection_members, collection_guid=_guid(current), - output_format="JSON") + listed = _members(client, _guid(current)) except Exception as exc: # noqa: BLE001 if is_gone_error(exc): # Not visible (zoned away from the reader) or deleted: what it held is no longer @@ -246,7 +274,7 @@ def read_consumer_tree(client, *, root_qn: str, consumer_prefix: str, key: Membe if not roots: return _not_read(out, f"the root {root_qn} was not found, or is not visible to {identity}") try: - listed = _call(client.get_collection_members, collection_guid=_guid(roots[0]), output_format="JSON") + listed = _members(client, _guid(roots[0])) except Exception as exc: # noqa: BLE001 return _not_read(out, f"the members of the root {root_qn} could not be read: {exc}") folders = [m for m in listed if is_folder(m)] diff --git a/pyegeria/view/saved_query.py b/pyegeria/view/saved_query.py index 3b265925..9d5a240f 100644 --- a/pyegeria/view/saved_query.py +++ b/pyegeria/view/saved_query.py @@ -215,18 +215,32 @@ def _not_measured(name, mode, output, reason): return _result(name, mode, output, state="not_established", reason=reason, absence="not_measured") -def _read_pages(fetch, page_size: int, max_pages: int) -> Tuple[List[Dict[str, Any]], bool]: - """Every element `fetch(start_from, page_size)` returns, paging until an empty page. Returns - (elements, capped): capped when `max_pages` pages were read and the next was not shown to be empty.""" +PAGING_STALLED = "paging did not advance" + + +def _read_pages(fetch, page_size: int, max_pages: int) -> Tuple[List[Dict[str, Any]], bool, Optional[str]]: + """Every distinct element `fetch(start_from, page_size)` returns, paging until an empty page. Returns + (elements, capped, note): + - capped: `max_pages` pages each brought new elements and the next was not shown to be empty; + - note: set when a page brought nothing new (a server that ignores startFrom returns the same page again): + the read stops there, says so, and is NOT capped. Until 6.2.36 such repetition was counted, page after page, + and a 3-member Results Set read as "at least 60" (ISSUE-185).""" found: List[Dict[str, Any]] = [] + seen: set = set() start = 0 for _ in range(max_pages): page = _elements(fetch(start, page_size)) if not page: - return found, False - found.extend(page) + return found, False, None + fresh = [e for e in page if (_guid(e) or id(e)) not in seen] + if not fresh: + return found, False, (f"{PAGING_STALLED}: the read from position {start} returned only elements " + f"already read, so it stopped at the {len(found)} distinct ones") + for e in fresh: + seen.add(_guid(e) or id(e)) + found.extend(fresh) start += len(page) - return found, True + return found, True, None def saved_query(client, name: str, mode: str = "cached", output: str = "count", @@ -363,7 +377,7 @@ def saved_query(client, name: str, mode: str = "cached", output: str = "count", out = _live(client, name, output, method, body, page_size, max_pages) out["how"] = f"{method} on this client's platform" + (f"; {note}" if note else "") if registration_note: - out["note"] = registration_note + out["note"] = f"{out['note']}; {registration_note}" if out.get("note") else registration_note if declared: out["params"] = used if out.get("subtitle") and out.get("asOf"): @@ -613,7 +627,7 @@ def _cached(client, name, output, additional, page_size, max_pages, kept_current return _not_measured(name, "cached", output, "the saved query has never been refreshed, so its " "Results Set holds no answer yet (not an empty answer)") try: - members, capped = _read_pages( + members, capped, paging_note = _read_pages( lambda start, size: client.get_collection_members(collection_guid=results_set, start_from=start, page_size=size, output_format="JSON"), page_size, max_pages) @@ -622,7 +636,7 @@ def _cached(client, name, output, additional, page_size, max_pages, kept_current return _result(name, "cached", output, state="not_established", absence="not_permitted", reason="the saved query's Results Set is not visible to you") return _not_measured(name, "cached", output, f"its Results Set could not be read ({type(exc).__name__})") - out = _answer(name, "cached", output, members, capped, as_of) + out = _answer(name, "cached", output, members, capped, as_of, paging_note) if kept_current: out["keptCurrentBy"] = "Egeria (Smart Collection, re-run about every 30 minutes from the stored request)" when = f" \u00b7 as of {as_of}" if as_of else " \u00b7 no refresh time recorded" @@ -650,7 +664,7 @@ def _live(client, name, output, method, body, page_size, max_pages): fn = getattr(client, method) now = datetime.now(timezone.utc).isoformat(timespec="seconds") try: - found, capped = _read_pages( + found, capped, paging_note = _read_pages( lambda start, size: fn(body={**body, "startFrom": start, "pageSize": size, "graphQueryDepth": 0}), page_size, max_pages) except Exception as exc: # noqa: BLE001 @@ -658,16 +672,20 @@ def _live(client, name, output, method, body, page_size, max_pages): return _result(name, "live", output, state="not_established", absence="not_permitted", reason="Egeria refused the saved query's request for you") return _not_measured(name, "live", output, f"the saved query's request failed ({type(exc).__name__})") - return _answer(name, "live", output, found, capped, now) + return _answer(name, "live", output, found, capped, now, paging_note) -def _answer(name, mode, output, elements, capped, as_of): +def _answer(name, mode, output, elements, capped, as_of, note=None): n = len(elements) listed = [_summary(e) for e in elements] if output == "list" else None if n == 0: - return _result(name, mode, output, state="nothing_found", absence="nothing_found", count=0, - elements=listed, as_of=as_of, reason="the saved query's answer is empty") - return _result(name, mode, output, state="measured", count=n, elements=listed, capped=capped, as_of=as_of) + out = _result(name, mode, output, state="nothing_found", absence="nothing_found", count=0, + elements=listed, as_of=as_of, reason="the saved query's answer is empty") + else: + out = _result(name, mode, output, state="measured", count=n, elements=listed, capped=capped, as_of=as_of) + if note: + out["note"] = note + return out # ── deleting a saved query (6.2.35) ── diff --git a/pyproject.toml b/pyproject.toml index 2f711204..545188d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [project] name = "pyegeria" -version = "6.2.35" +version = "6.2.36" license = 'Apache-2.0' license-files = ["LICENSE"] authors = [{name = "Dan Wolfson", email = "dan.wolfson@pdr-associates.com"},] diff --git a/tests/micro-tests/test_collection_members_paging.py b/tests/micro-tests/test_collection_members_paging.py new file mode 100644 index 00000000..99159a81 --- /dev/null +++ b/tests/micro-tests/test_collection_members_paging.py @@ -0,0 +1,133 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright Contributors to the ODPi Egeria project. +"""ISSUE-185 (6.2.36): get_collection_members ignored start_from and page_size. + +They are the method's own parameters, so they never reached **kwargs, and they were never passed on: every call +read the first page. A reader paging until an empty page (saved_query) therefore re-read the same members until its +bound, and a 3-member Results Set read as "at least 60" on the Portal and in EA (the Architect's live Route B +read-back, 2026-11-11). Also: paging given as arguments was dropped whenever a caller passed its own body. + +The fake server below answers members/ requests the way Egeria pages: by the body's startFrom and pageSize. +""" +import asyncio +import json + +import pytest + +from pyegeria.core._server_client import _with_paging +from pyegeria.omvs.collection_manager import CollectionManager +from pyegeria.view import saved_query as sq + +pytestmark = pytest.mark.unit + +MEMBERS = [{"elementHeader": {"guid": f"m{i}", "type": {"typeName": "DataSet"}}, + "properties": {"qualifiedName": f"Asset::{i}", "displayName": f"Asset {i}"}} for i in range(7)] + + +class _Response: + def __init__(self, body): + self._body = body + + def json(self): + return self._body + + +@pytest.fixture +def client(monkeypatch): + monkeypatch.setattr(CollectionManager, "check_connection", lambda self: "test") + c = CollectionManager("view-server", "https://localhost:1", "user", "pwd") + c.sent = [] + + async def server(method, url, body=None, *a, **kw): + req = json.loads(body) if isinstance(body, str) else (body or {}) + c.sent.append(req) + start, size = req.get("startFrom", 0), req.get("pageSize", 0) or len(MEMBERS) + page = MEMBERS[start:start + size] + return _Response({"elements": page} if page else {"element": "No elements found"}) + + c._async_make_request = server + return c + + +def _members(c, **kw): + return asyncio.run(c._async_get_collection_members(collection_guid="rs-1", output_format="JSON", **kw)) + + +def _guids(found): + return [e["elementHeader"]["guid"] for e in found] if isinstance(found, list) else found + + +def test_two_pages_differ(client): + assert _guids(_members(client, start_from=0, page_size=3)) == ["m0", "m1", "m2"] + assert _guids(_members(client, start_from=3, page_size=3)) == ["m3", "m4", "m5"] + assert _guids(_members(client, start_from=6, page_size=3)) == ["m6"] + assert _members(client, start_from=9, page_size=3) == "No elements found" + + +def test_the_request_body_carries_the_paging(client): + _members(client, start_from=50, page_size=50) + assert client.sent[-1]["startFrom"] == 50 and client.sent[-1]["pageSize"] == 50 + assert client.sent[-1]["class"] == "ResultsRequestBody" + + +def test_a_callers_body_gets_the_calls_paging_unless_it_sets_its_own(client): + _members(client, body={"class": "ResultsRequestBody", "limitResultsByStatus": ["ACTIVE"]}, start_from=3, page_size=3) + assert (client.sent[-1]["startFrom"], client.sent[-1]["pageSize"]) == (3, 3) + assert client.sent[-1]["limitResultsByStatus"] == ["ACTIVE"] + _members(client, body={"class": "ResultsRequestBody", "pageSize": 2}, start_from=3, page_size=3) + assert (client.sent[-1]["startFrom"], client.sent[-1]["pageSize"]) == (3, 2) # the body's own wins + + +@pytest.mark.parametrize(("body", "start", "size", "expected"), [ + ({"a": 1}, 0, 0, {"a": 1}), + ({"a": 1}, 5, 10, {"a": 1, "startFrom": 5, "pageSize": 10}), + ({"start_from": 2}, 5, 10, {"start_from": 2, "pageSize": 10}), + ({"startFrom": 2, "pageSize": 4}, 5, 10, {"startFrom": 2, "pageSize": 4}), +]) +def test_with_paging(body, start, size, expected): + assert _with_paging(body, start, size) == expected + assert body == {k: v for k, v in body.items()} # the caller's dict is not changed + + +def test_saved_query_reads_every_member_once_through_the_real_call(client): + found, capped, note = sq._read_pages( + lambda start, size: client.get_collection_members(collection_guid="rs-1", start_from=start, page_size=size, + output_format="JSON"), + 3, 20) + assert _guids(found) == [f"m{i}" for i in range(7)] and capped is False and note is None + + +# ── a server that ignores paging (what laz showed): repetition is never a count, and never "capped" ── + +def test_a_page_that_repeats_stops_the_read_and_says_so(): + first3 = MEMBERS[:3] + found, capped, note = sq._read_pages(lambda start, size: list(first3), 50, 20) + assert _guids(found) == ["m0", "m1", "m2"] and capped is False + assert note.startswith("paging did not advance: the read from position 3 returned only elements already read") + + +def test_a_genuinely_long_read_is_still_capped(): + found, capped, note = sq._read_pages( + lambda start, size: [{"elementHeader": {"guid": f"g{start + i}"}} for i in range(size)], 5, 4) + assert len(found) == 20 and capped is True and note is None + + +def test_the_tile_the_architect_saw_reads_3_not_at_least_60(): + class Stuck: + """laz on 2026-11-11: (0,50), (3,50), (50,50), (0,2), (2,2) all returned the same 3 members.""" + platform_url, view_server = "https://localhost:9443", "qs-view-server" + + def find_metadata_elements(self, body=None, **kw): + return [{"elementHeader": {"guid": "sq-1", "type": {"typeName": "SavedQuery"}}, + "properties": {"qualifiedName": "SavedQuery::stuck", "additionalProperties": { + "resultsSetGuid": "rs-1", "lastRefreshedTime": "2026-11-11T10:00:00+00:00"}}}] + + def get_related_elements(self, *a, **kw): + return "No elements found" + + def get_collection_members(self, **kw): + return list(MEMBERS[:3]) + + out = sq.saved_query(Stuck(), "SavedQuery::stuck") + assert out["value"] == 3 and out["display"] == "3" and not out.get("capped") + assert "paging did not advance" in out["note"] diff --git a/tests/micro-tests/test_dashboard_folders.py b/tests/micro-tests/test_dashboard_folders.py index 95361836..38a9c580 100644 --- a/tests/micro-tests/test_dashboard_folders.py +++ b/tests/micro-tests/test_dashboard_folders.py @@ -53,10 +53,12 @@ def get_collections_by_name(self, name, metadata_element_type=None, output_forma and metadata_element_type in (None, e["type"])] return copy.deepcopy(hits) or "No elements found" - def get_collection_members(self, collection_guid=None, output_format="JSON", **_): + def get_collection_members(self, collection_guid=None, output_format="JSON", start_from=0, page_size=0, **_): if collection_guid in self.failing: raise RuntimeError("HTTP 500 from the view server") - return [self.element(g) for g in self.members.get(collection_guid, [])] or "No elements found" + guids = self.members.get(collection_guid, []) + guids = guids[start_from:start_from + page_size] if page_size else guids[start_from:] + return [self.element(g) for g in guids] or "No elements found" async def _sheet(fake, name): @@ -212,3 +214,31 @@ async def test_an_unreadable_consumer_makes_the_index_partial(tree): idx = dash.build_dashboard_consumer_index(tree["fake"]) assert idx["status"] == "partial" and "Portal" in idx["reason"] assert idx["index"] == {"Ops": ["EgeriaAdvisor", "Portal"]} + + +def test_a_folder_larger_than_one_page_is_read_to_the_end(tree, monkeypatch): + """6.2.36 (LD-3 note N2): the walk pages until an empty page; it used to be one unpaged read.""" + monkeypatch.setattr(folders, "MEMBERS_PAGE", 2) + fake = tree["fake"] + for i in range(5): + fake.put(tree["portal"], fake.add_entity("Report", f"DeployedReport::R{i}", f"R{i}")) + walk = folders.walk_folder(fake, fake.element(tree["portal"]), recursive=False, + consumer_prefix=dash.DASHBOARD_CONSUMER_PREFIX) + assert len(walk.members) == 7 # Ops, the Exec folder and five Reports, over four pages + + +def test_a_folder_over_the_bound_is_not_read_as_a_short_one(tree, monkeypatch): + monkeypatch.setattr(folders, "MEMBERS_PAGE", 1) + monkeypatch.setattr(folders, "MEMBERS_MAX_PAGES", 1) + listing = dash.build_dashboard_consumer_index(tree["fake"]) + # the root itself (two consumers) is over the bound here, so the whole tree is "not read", with the reason + assert listing["status"] == "not read" and "not read to the end" in listing["reason"] and listing["index"] == {} + + +def test_a_server_that_ignores_paging_ends_the_walk(tree, monkeypatch): + fake = tree["fake"] + real = fake.get_collection_members + monkeypatch.setattr(fake, "get_collection_members", lambda **kw: real(**{**kw, "start_from": 0})) + walk = folders.walk_folder(fake, fake.element(tree["portal"]), recursive=True, + consumer_prefix=dash.DASHBOARD_CONSUMER_PREFIX) + assert sorted(m["properties"]["qualifiedName"] for m in walk.members) == ["Dashboard::Board", "Dashboard::Ops"] diff --git a/tests/micro-tests/test_rs_consumer_folders.py b/tests/micro-tests/test_rs_consumer_folders.py index 9da67505..99b50d44 100644 --- a/tests/micro-tests/test_rs_consumer_folders.py +++ b/tests/micro-tests/test_rs_consumer_folders.py @@ -76,13 +76,20 @@ def get_collections_by_name(self, name, metadata_element_type=None, output_forma and (metadata_element_type in (None, e["elementHeader"]["type"]["typeName"]))] return copy.deepcopy(hits) or "No elements found" - def get_collection_members(self, collection_guid=None, output_format="JSON", **_): - self.member_reads.append(collection_guid) + def get_collection_members(self, collection_guid=None, output_format="JSON", start_from=0, page_size=0, **_): + if start_from == 0: # one entry per folder read; a read pages on to its empty page (6.2.36) + self.member_reads.append(collection_guid) if collection_guid in self.failing: raise RuntimeError("HTTP 500 from the view server") if collection_guid in self.refusals: raise self.refusals[collection_guid] - return copy.deepcopy(self.members.get(collection_guid)) or "No elements found" + return copy.deepcopy(self._page(self.members.get(collection_guid), start_from, page_size)) or "No elements found" + + @staticmethod + def _page(items, start_from, page_size): + """Egeria's paging: startFrom/pageSize slice the members (pageSize 0 is the server's default, here all).""" + items = list(items or []) + return items[start_from:start_from + page_size] if page_size else items[start_from:] def get_collection_by_guid(self, guid, output_format="JSON", **_): e = self.by_guid.get(guid) diff --git a/tests/micro-tests/test_rs_egeria_tier.py b/tests/micro-tests/test_rs_egeria_tier.py index bf77a3f5..e6c5ed78 100644 --- a/tests/micro-tests/test_rs_egeria_tier.py +++ b/tests/micro-tests/test_rs_egeria_tier.py @@ -92,8 +92,10 @@ def get_collections_by_name(self, name, metadata_element_type=None, output_forma if name in (e["properties"]["qualifiedName"], e["properties"]["displayName"])] return hits or "No elements found" - def get_collection_members(self, collection_guid=None, output_format="JSON", **_): - return copy.deepcopy(self.members.get(collection_guid)) or "No elements found" + def get_collection_members(self, collection_guid=None, output_format="JSON", start_from=0, page_size=0, **_): + items = list(self.members.get(collection_guid) or []) + items = items[start_from:start_from + page_size] if page_size else items[start_from:] + return copy.deepcopy(items) or "No elements found" def get_collection_by_guid(self, guid, output_format="JSON", **_): self.full_fetches.append(guid) diff --git a/uv.lock b/uv.lock index 66d6bc28..3a82a1f3 100644 --- a/uv.lock +++ b/uv.lock @@ -2238,7 +2238,7 @@ sdist = { url = "https://files.pythonhosted.org/packages/f8/f6/8f49005d581cff883 [[package]] name = "pyegeria" -version = "6.2.35" +version = "6.2.36" source = { editable = "." } dependencies = [ { name = "altair" },