From 3adfcacd1f2c62cd19385e7dca215e69c4eae9c1 Mon Sep 17 00:00:00 2001 From: Dan Wolfson Date: Fri, 2 Oct 2026 15:46:04 -0500 Subject: [PATCH] fix(my_egeria): My Profile performance, exec_report_spec depth, packaging and serve fixes pyegeria - exec_report_spec silently dropped a caller's graph_query_depth (it copies only a spec's declared params), so report-spec calls always ran at depth 3. It now forwards graph_query_depth when the target method accepts it; other undeclared params are still not forwarded (ISSUE-119). - Packaging: the wheel installed my_egeria one level too deep (site-packages/my_egeria/my_egeria/...), so the my_egeria, my_profile, serve_my_egeria and serve_my_profile commands failed in every pip install. packages.find now also searches my_egeria/ with namespaces off, so the app installs as the top-level my_egeria package; pyegeria/config and commands/deprecated gain __init__.py so they keep shipping. A clean-build diff shows the wheel is otherwise identical, and my_profile.tcss now ships (ISSUE-118). my_egeria - serve_my_egeria / serve_my_profile used the `textual serve` CLI (textual-dev, dev-only); they now use the textual-serve library and honour MY_EGERIA_PUBLIC_URL / MY_PROFILE_PUBLIC_URL. Removed the stale [app.*] textual-web sections from my_egeria/pyproject.toml. - The startup check required EGERIA_SERVER / EGERIA_BASE_URL with no defaults, so following the README produced an error popup; it now derives them from the documented EGERIA_VIEW_SERVER / EGERIA_PLATFORM_URL. - My Profile graph_query_depth tuning (measured live on the quickstart): - startup "my collections": depth 0 (~70s -> 0.6s) - profile fetched once, formatted locally for both views (identical output) - to-dos: depth passed as a keyword (params= was ignored), 5.7s -> 0.6s - bookmarks members/lookup, term/data-dictionary/collection details, subscriptions, comments, data-set GUID lookups: depth 0 - glossary folders and root-collection members: fetch only the selected element at depth 1 (needed once depth 0 took effect; also fixes the root collection tree working only for the first row) - product and capability details: depth 1; team members unchanged (need 2+) Startup now shows the full profile ~4s after the splash, down from ~82s. Docs: developer guide section on choosing graph_query_depth; my_egeria README, handoff and integration docs (textual-serve, packaging change, Python 3.13); My Profile manual; ISSUE-118/119/120 (120: Textual fails on Python 3.14, use 3.13). Signed-off-by: Dan Wolfson --- PYEGERIA_ISSUES.md | 72 +++++++++++++++++++ commands/deprecated/__init__.py | 2 + docs/developer_guide_pyegeria_textual.md | 38 +++++++++- docs/my_profile_app_manual.md | 8 ++- my_egeria/EGERIA_WORKSPACES_INTEGRATION.md | 16 +++-- .../HANDOFF_egeria_workspaces_my_egeria.md | 32 ++++++--- my_egeria/README.md | 28 +++++--- .../My_Profile/SearchForTermScreen.py | 3 +- .../My_Profile/SelectionOverviewScreen.py | 15 ++-- .../DemoCode/My_Profile/ShowCommentsScreen.py | 2 +- .../My_Profile/ViewSubscriptionsScreen.py | 1 + .../DemoCode/My_Profile/bookmarks_handler.py | 6 +- .../DemoCode/My_Profile/my_profile_app.py | 24 ++++--- .../My_Profile/shop_for_data_handler.py | 40 +++++++++-- .../DemoCode/My_Profile/team_roles_handler.py | 3 +- my_egeria/my_egeria/README.md | 2 +- my_egeria/my_egeria/serve.py | 59 +++++++++------ my_egeria/my_egeria/startup_check.py | 5 ++ .../my_egeria/tests/test_startup_check.py | 9 +++ my_egeria/pyproject.toml | 10 +-- pyegeria/config/__init__.py | 2 + pyegeria/view/format_set_executor.py | 23 ++++++ pyproject.toml | 10 ++- .../my_profile/test_bookmarks_handler.py | 3 +- ...test_exec_report_spec_graph_query_depth.py | 70 ++++++++++++++++++ 25 files changed, 402 insertions(+), 81 deletions(-) create mode 100644 commands/deprecated/__init__.py create mode 100644 pyegeria/config/__init__.py create mode 100644 tests/micro-tests/test_exec_report_spec_graph_query_depth.py diff --git a/PYEGERIA_ISSUES.md b/PYEGERIA_ISSUES.md index 3554de94..58c0aae9 100644 --- a/PYEGERIA_ISSUES.md +++ b/PYEGERIA_ISSUES.md @@ -1316,6 +1316,62 @@ changed beyond that one status correction and this note. --- +### ISSUE-118: the pyegeria wheel installed `my_egeria` one level too deep, so `my_egeria`, `my_profile`, `serve_my_egeria` and `serve_my_profile` failed in every pip install + +**Layer:** Pyegeria (packaging) · **Status:** fixed 2026-10-02 · **Found:** +2026-10-02, preparing to serve the new My Profile app from the Egeria-Workspaces portal. + +**What:** `[tool.setuptools.packages.find]` searched only from the repo root, so the +app's real package (`my_egeria/my_egeria/`, inside the `my_egeria/` uv workspace +member) shipped as `site-packages/my_egeria/my_egeria/...`. The four console scripts +point at `my_egeria.main`, `my_egeria.serve`, `my_egeria.DemoCode...`, and the app's +own code imports `from my_egeria.`, so none of it resolved outside this repo's +dev venv (where the workspace member is installed editable). The portal survived only +because its own script launched `my_profile_app.py` by **file path**, found with a glob +for the nested layout. + +**Fixed:** `where = [".", "my_egeria"]` with `namespaces = false`, so the inner +package installs as the top-level `my_egeria`. Two folders that had only shipped as +namespace packages (`pyegeria/config`, `commands/deprecated`) gained an +`__init__.py`. A clean-build comparison showed the wheel is otherwise identical: the +same 480 files, with `my_egeria/...` now top-level, plus the two new `__init__.py`. +`my_profile.tcss` now ships too, so the portal Dockerfile's manual copy is unnecessary. +**Downstream impact:** anything launching the app by the old nested file path must +switch to the entry points (`serve_my_profile` etc.). + +**Related, same day:** `serve_my_egeria`/`serve_my_profile` shelled out to the +`textual serve` command, which comes from `textual-dev` (a dev-only dependency), so +they also failed in a plain install. They now use the `textual-serve` library +directly, and honour `MY_EGERIA_PUBLIC_URL`/`MY_PROFILE_PUBLIC_URL` for proxied +deployments. + +--- + +### ISSUE-119: `exec_report_spec` silently dropped a caller's `graph_query_depth`, so report-spec calls always ran at depth 3 + +**Layer:** Pyegeria · **Status:** fixed 2026-10-02 · **Found:** 2026-10-02, +performance review of the My Profile and MyEgeria apps. + +**What:** the synchronous `exec_report_spec` copies only a report spec's declared +`required_params`/`optional_params` into the call, and no spec declares +`graph_query_depth`. So `params={"search_string": "*", "graph_query_depth": 0}` +reached Egeria at the SDK default depth of 3, with no warning. The My Profile app asked for +depth 0 in about ten places and got none of it. Live, at the effective depth 3: the +13-glossary list and the root-collection list timed out at 90 s, the data +dictionaries took about 39 s and the product catalogue 42 s. At depth 0 they take +0.3–0.8 s. (The async path already forwarded it via `_merge_signature_params`.) + +**Fixed:** `graph_query_depth` is now forwarded when the caller supplies it and the +target method accepts it (as a named parameter or `**kwargs`). This is deliberately narrower than the +async path, which forwards *every* caller param to `**kwargs` methods. Other +undeclared params are still not forwarded. Test: +`tests/micro-tests/test_exec_report_spec_graph_query_depth.py`. **Watch for:** +callers that asked for depth 0 but needed related elements were working only *because* +of this bug. My Profile's glossary folders and root-collection members were two such +cases, fixed in the same change by fetching the selected element at depth 1. + +--- + ### ISSUE-116: `get_my_actors` always failed and `get_my_user_identities`/`get_my_roles` always returned nothing — same type-filter defect as ISSUE-115, hidden by tests that swallowed errors **Layer:** Pyegeria · **Status:** fixed 2026-10-02 · **Found:** 2026-10-02 @@ -7972,6 +8028,22 @@ deployment-timing issue, not a code defect — see ISSUE-12, below. ## Not a bug / n/a +### ISSUE-120: Textual apps (My Profile, MyEgeria) crash on Python 3.14 with `assert task is not None` in `textual/rlock.py` + +**Layer:** not pyegeria (Textual / Python 3.14) · **Status:** n/a, workaround: use +Python 3.13 · **Found:** 2026-10-02, testing the new My Profile app for the portal +image (`python:3.14-slim`). + +**What:** Textual's `RLock.acquire` asserts `asyncio.current_task()` is not None, +which fails under Python 3.14. Reproduced with the new My Profile app on both Textual +6.1.0 (the portal's pin) and 8.2.8, the latest release, on 3.14. Both start cleanly on 3.13. +Textual's current `main` still has the same code. The older My Profile apparently +didn't reach that path; the new parallel profile loading does. The same failure is +noted in `.github/workflows/release.yml`, which pins CI to Python 3.13 for this reason. +**Action:** build Textual app images on Python 3.13; revisit when Textual supports 3.14. + +--- + ### ISSUE-88: no `GovernanceZone` create or lookup anywhere in pyegeria — a zone can be *referenced* by every search and classification, but not made **Layer:** Pyegeria · **Status: n/a — not a bug, corrected 2026-09-05 by dwolfson.** diff --git a/commands/deprecated/__init__.py b/commands/deprecated/__init__.py new file mode 100644 index 00000000..c136d40c --- /dev/null +++ b/commands/deprecated/__init__.py @@ -0,0 +1,2 @@ +"""Package marker: ships this directory now that wheel package discovery +doesn't pick up namespace packages (see [tool.setuptools.packages.find]).""" diff --git a/docs/developer_guide_pyegeria_textual.md b/docs/developer_guide_pyegeria_textual.md index 76f991f0..d22d359e 100644 --- a/docs/developer_guide_pyegeria_textual.md +++ b/docs/developer_guide_pyegeria_textual.md @@ -124,7 +124,7 @@ source .venv/bin/activate **Using pyegeria in your own project** instead: ```bash -pip install pyegeria textual textual-dev +pip install pyegeria textual textual-dev # textual-dev only for the dev console and `textual run` ``` ### Tell pyegeria where Egeria is @@ -309,6 +309,37 @@ pyegeria has hundreds of methods. To explore them: - The REST calls behind each method are recorded in `.http` files under `pyegeria/http clients/`, which is useful when you need to see exactly what is sent. +### Ask only for the relationships you need: `graph_query_depth` + +Every pyegeria `find_*`/`get_*` call sends a `graph_query_depth` that tells Egeria how many +levels of related elements to compute for each result. **The default is 3**, which is rich but +expensive, and the cost grows with the number of results. Measured on the quickstart server +while tuning the My Profile app: + +| Call | Default depth (3) | Depth 0 | +|---|---|---| +| List of 13 glossaries | timed out at 90 s | 0.3 s | +| List of 100 collections (My Profile startup) | about 70 s | 0.6 s | +| Members of a 7-element collection | timed out at 30 s | 0.3 s | + +Choose the depth from what your screen actually shows: + +- **Lists and tables of names, descriptions, GUIDs** (header and properties only): use + **`graph_query_depth=0`**. +- **A detail view of one selected element that shows its related elements** (a glossary's + folders, a collection's members): fetch **just that element at depth 1** when it is + selected, rather than loading the whole list at depth 1. +- **Some views need more.** In My Profile, the profile's Teams, Communities and Projects and a + team's individual members disappear below depth 2. + +Pass it as a keyword: `client.find_glossaries("*", graph_query_depth=0)`. Through +`exec_report_spec`, put it in `params` (`params={"search_string": "*", "graph_query_depth": 0}`); +this is forwarded to the method from pyegeria 6.1.26. Earlier versions silently dropped it. +A `params=` keyword on an SDK method itself is **not** a way to pass it: it is ignored. + +To check a lower depth is safe, run the call at both depths with `output_format="JSON"` (or the +`DICT` your screen uses) and compare the fields your code reads. + --- ## 6. Textual essentials (Steps 2 and 3) @@ -960,8 +991,11 @@ python examples/developer_guide/capture_screenshots.py - **Results are empty, or a column is missing.** The report spec doesn't define that column, or `graph_query_depth` is too low for related data. Try `output_format="JSON"` to see everything Egeria returned. -- **Slow responses or time-outs.** Use `graph_query_depth=0` unless you need relationships, +- **Slow responses or time-outs.** Use `graph_query_depth=0` unless you need relationships + (see [Ask only for the relationships you need](#ask-only-for-the-relationships-you-need-graph_query_depth)), and `page_size` to limit how many results come back. +- **`assert task is not None` in `textual/rlock.py`.** You are on Python 3.14, which Textual + does not yet support. Use Python 3.13. - **"Parameter ... is null" from Egeria when the parameter was set.** Your program is running under a different Python than your venv. Check `which python` and `which textual`. - **An action does nothing.** Check for two `@on` handlers with the same method name in one diff --git a/docs/my_profile_app_manual.md b/docs/my_profile_app_manual.md index 24cd9b41..9cfb1287 100644 --- a/docs/my_profile_app_manual.md +++ b/docs/my_profile_app_manual.md @@ -76,16 +76,20 @@ my_profile # installed console script, runs from any directory # or, from the app folder: cd my_egeria/my_egeria/DemoCode/My_Profile python my_profile_app.py -# or, with the Textual developer console available: +# or, with the Textual developer console (needs textual-dev, a dev dependency): textual run --dev my_profile_app.py ``` +Use Python 3.13: Textual currently fails on Python 3.14 (an assertion in `textual/rlock.py` at startup). + To serve the app in a web browser instead of a terminal: ```bash -serve_my_profile # textual serve on $MY_EGERIA_HOST:$MY_PROFILE_PORT (default 0.0.0.0:8020) +serve_my_profile # textual-serve on $MY_EGERIA_HOST:$MY_PROFILE_PORT (default 0.0.0.0:8020) ``` +Behind a reverse proxy, set `MY_PROFILE_PUBLIC_URL` (or `MY_EGERIA_PUBLIC_URL`) to the URL browsers use, e.g. `https://localhost:8843/my-egeria`, so the page's asset and WebSocket URLs are same-origin. + ## The Splash Screen and Changing User When the app starts it shows a welcome card ("Welcome to My_Profile for Egeria Users, *user*!") while your profile loads from Egeria in the background. diff --git a/my_egeria/EGERIA_WORKSPACES_INTEGRATION.md b/my_egeria/EGERIA_WORKSPACES_INTEGRATION.md index 0c30257c..42ad3879 100644 --- a/my_egeria/EGERIA_WORKSPACES_INTEGRATION.md +++ b/my_egeria/EGERIA_WORKSPACES_INTEGRATION.md @@ -11,10 +11,13 @@ to host my_egeria Textual apps as browser-accessible tools via the portal. ## How it works -`textual serve` turns any Textual app into a browser app — each WebSocket +`serve_my_profile` / `serve_my_egeria` use the `textual-serve` library (installed +with pyegeria) to turn the Textual app into a browser app — each WebSocket connection gets its own isolated app instance. The portal button simply links to the app's URL (new tab or iframe). No code difference between terminal and -browser modes; the same installed app serves both. +browser modes; the same installed app serves both. Behind a proxy, set +`MY_EGERIA_PUBLIC_URL` (or `MY_PROFILE_PUBLIC_URL`) to the URL browsers use, so +the page's asset and WebSocket URLs are same-origin. --- @@ -89,7 +92,7 @@ prompts the user for credentials in the browser. No portal changes needed. ### Option B — Per-session process spawning (proper multi-user) The portal's login flow calls a small management API that: -1. Spawns `textual serve --port serve_my_profile` with the +1. Spawns `serve_my_profile` with `MY_PROFILE_PORT=` and the authenticated user's credentials as env vars. 2. Returns the URL to the portal, which opens it. 3. Cleans up (kills the process) on session logout / timeout. @@ -115,7 +118,7 @@ location /my-profile/ { } ``` -The WebSocket upgrade headers are **required** — textual serve uses WebSockets. +The WebSocket upgrade headers are **required** — textual-serve uses WebSockets. The portal button then links to `/my-profile/` instead of `localhost:8020`. @@ -146,8 +149,9 @@ The compose service above uses `python:3.12-slim`. In practice, use a shared base image that has `pyegeria` (and therefore `my_egeria`) already installed: ```dockerfile -FROM python:3.12-slim -RUN pip install pyegeria # installs my_egeria and all entry points +FROM python:3.13-slim # not 3.14: Textual fails on 3.14 (textual/rlock.py) +RUN pip install pyegeria # installs my_egeria, textual, textual-serve and all entry points +CMD ["serve_my_profile"] ``` Or reuse the existing `Dockerfile-jupyter` / `Dockerfile-egeria-platform` diff --git a/my_egeria/HANDOFF_egeria_workspaces_my_egeria.md b/my_egeria/HANDOFF_egeria_workspaces_my_egeria.md index cb23bcf1..f63c61b3 100644 --- a/my_egeria/HANDOFF_egeria_workspaces_my_egeria.md +++ b/my_egeria/HANDOFF_egeria_workspaces_my_egeria.md @@ -22,10 +22,22 @@ lists only what is **new** and what egeria-workspaces must add/change. | Listen port env | `MY_EGERIA_PORT` (default `8021`) | Both entry points are installed by `pip install pyegeria` (no separate package). -`serve_my_egeria` runs `textual serve` against the app; each browser WebSocket +`serve_my_egeria` serves the app with the `textual-serve` library (a pyegeria +dependency — no `textual` CLI or `textual-dev` needed); each browser WebSocket connection gets its own isolated app instance — no code difference between terminal and browser modes. +**Requires a pyegeria release with the 2026-10 packaging fix.** Earlier wheels +installed the app one level too deep (`site-packages/my_egeria/my_egeria/...`), so +the `my_egeria`, `my_profile`, `serve_my_egeria` and `serve_my_profile` commands +failed in every pip install. The app now installs as the top-level `my_egeria` +package (`site-packages/my_egeria/...`). Anything that launched the app by **file +path** under the old nested layout must switch to the entry points. + +**Use Python 3.13, not 3.14.** Textual (6.1.0 through the current 8.2.8) fails on +Python 3.14 with `assert task is not None` in `textual/rlock.py`; My Profile hits +it at startup. Build the image on `python:3.13-slim`. + ### Port allocation (current) | App | Port | Serve entry point | @@ -42,8 +54,9 @@ terminal and browser modes. The image used for the Textual app services must have a pyegeria build that includes the `serve_my_egeria` entry point and the `my_egeria_app` module rename. -If the image pins an older pyegeria, bump it. No new dependencies were added -(`textual`, `textual-serve`, `textual-web` were already required). +If the image pins an older pyegeria, bump it. Do not pin an older `textual`; +let pyegeria's own dependency choose it. No extra packages are needed: `textual` +and `textual-serve` come with pyegeria. ### 2. Add a compose service (quickstart) @@ -115,14 +128,16 @@ file. They must be present in the `my-egeria` service environment: | `EGERIA_VIEW_SERVER` | `qs-view-server` | View server name | | `EGERIA_USER` | `erinoverview` | Active persona (quickstart) | | `EGERIA_USER_PASSWORD` | `secret` | Password (quickstart) | -| `MY_EGERIA_HOST` | `0.0.0.0` | Listen host for textual serve | -| `MY_EGERIA_PORT` | `8021` | Listen port for textual serve | +| `MY_EGERIA_HOST` | `0.0.0.0` | Listen host for textual-serve | +| `MY_EGERIA_PORT` | `8021` | Listen port for textual-serve | +| `MY_EGERIA_PUBLIC_URL` | `https:///my-egeria` | URL browsers use when behind a proxy, so page and WebSocket URLs are same-origin. `MY_PROFILE_PUBLIC_URL` is the My Profile equivalent; `MY_EGERIA_PUBLIC_URL` is used for either app if the app's own is not set. | --- ## Verifying the hand-off -1. **Terminal:** `my_egeria` launches the TUI. +1. **Terminal:** `my_egeria` launches the TUI (the startup check now uses the + same `EGERIA_*` variables and defaults as the table below). 2. **Local browser:** `MY_EGERIA_PORT=8021 serve_my_egeria`, then open `http://localhost:8021/`. 3. **Through the portal:** the `/my-egeria/` route loads the app and the @@ -137,8 +152,9 @@ If the app loads but cannot reach Egeria, recheck `EGERIA_PLATFORM_URL` / ## Notes / gotchas - The app module was renamed `my_egeria.my_egeria` → `my_egeria.my_egeria_app`. - egeria-workspaces should **not** reference the module path directly — only the - `serve_my_egeria` / `my_egeria` entry points, which are stable. + egeria-workspaces should **not** reference the module path or a file path + directly — only the `serve_my_egeria` / `serve_my_profile` / `my_egeria` entry + points, which are stable. (The packaging fix above moved the installed files.) - If you template the compose service, keep one `MY_*_PORT` per app; only `MY_EGERIA_HOST` is shared. - "Adding more apps" recipe lives in `EGERIA_WORKSPACES_INTEGRATION.md` diff --git a/my_egeria/README.md b/my_egeria/README.md index 1cb15128..05682765 100644 --- a/my_egeria/README.md +++ b/my_egeria/README.md @@ -14,15 +14,25 @@ If you have `uv` installed, you can sync the workspace from the root: uv sync ``` -## Running the app -You can run the app using: -```bash -uv run my-egeria -``` -or -```bash -python -m my_egeria.main -``` +## Running the apps +This package contains two Textual apps: + +- **My Profile** (`DemoCode/My_Profile/`) — the actively developed app, and the one + the Egeria-Workspaces portal serves: + ```bash + uv run my_profile # or: python -m my_egeria.DemoCode.My_Profile.my_profile_app + ``` +- **MyEgeria** — the original glossary/collection browser (not under active + development; several of its secondary screens are incomplete): + ```bash + uv run my-egeria # or: python -m my_egeria.main + ``` + +Both run in a terminal with the defaults below; set `EGERIA_USER` / +`EGERIA_USER_PASSWORD` to sign in as someone else (e.g. `peterprofile`, who has a +populated profile on the quickstart). For browser mode, see +`serve_my_profile` / `serve_my_egeria` in `EGERIA_WORKSPACES_INTEGRATION.md`. +Use Python 3.13 — Textual fails on Python 3.14. ## Configuration The app uses the following environment variables (with defaults): diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/SearchForTermScreen.py b/my_egeria/my_egeria/DemoCode/My_Profile/SearchForTermScreen.py index 5181a123..9404b0bc 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/SearchForTermScreen.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/SearchForTermScreen.py @@ -103,7 +103,8 @@ def search_for_the_term(self, search_term): try: self.search_result = exec_report_spec(format_set_name="Glossary-Terms", output_format="MD", - params={"search_string": search_term, "filter_string": search_term}, + params={"search_string": search_term, "filter_string": search_term, + "graph_query_depth": 0}, # term properties only view_server=self.view_server, view_url=self.platform_url, user=self.user, diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/SelectionOverviewScreen.py b/my_egeria/my_egeria/DemoCode/My_Profile/SelectionOverviewScreen.py index 2c1330bb..41ee4a3f 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/SelectionOverviewScreen.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/SelectionOverviewScreen.py @@ -133,7 +133,8 @@ def display_selected_term_details(self, term_GUID) -> Any: try: self.glossary_term_data = exec_report_spec(format_set_name="Glossary-Terms", output_format="MD", - params={"search_string": self.term_GUID, "filter_string": self.term_GUID}, + params={"search_string": self.term_GUID, "filter_string": self.term_GUID, + "graph_query_depth": 0}, # term properties only view_server=self.view_server, view_url=self.platform_url, user=self.user_name, @@ -173,7 +174,8 @@ def display_selected_digital_product(self, digital_product_GUID) -> Any: self.digital_product_data = exec_report_spec(format_set_name="Digital-Products-MyE", output_format="MD", params={"search_string": self.digital_product_GUID, - "filter_string": self.digital_product_GUID}, + "filter_string": self.digital_product_GUID, + "graph_query_depth": 1}, # shows members and assigned actors view_server=self.view_server, view_url=self.platform_url, user=self.user_name, @@ -217,7 +219,8 @@ def display_selected_data_dictionary(self, data_dictionary_GUID) -> Any: self.data_dictionary_data = exec_report_spec(format_set_name="Data-Dictionaries", output_format="MD", params={"search_string": self.data_dictionary_GUID, - "filter_string": self.data_dictionary_GUID}, + "filter_string": self.data_dictionary_GUID, + "graph_query_depth": 0}, # properties only view_server=self.view_server, view_url=self.platform_url, user=self.user_name, @@ -253,7 +256,8 @@ def display_selected_business_domain(self, business_domain_GUID) -> int: self.business_domain_data = exec_report_spec(format_set_name="BusinessCapabilities", output_format="DICT", params={"search_string": self.business_domain_GUID, - "filter_string": self.business_domain_GUID}, + "filter_string": self.business_domain_GUID, + "graph_query_depth": 1}, # shows Containing Members / Member Of view_server=self.view_server, view_url=self.platform_url, user=self.user_name, @@ -318,7 +322,8 @@ def display_selected_root_collection(self, root_collection_GUID) -> int: self.root_collection_data = exec_report_spec(format_set_name="Collections", output_format="MD", params={"search_string": self.root_collection_GUID, - "filter_string": self.root_collection_GUID}, + "filter_string": self.root_collection_GUID, + "graph_query_depth": 0}, # properties only view_server=self.view_server, view_url=self.platform_url, user=self.user_name, diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/ShowCommentsScreen.py b/my_egeria/my_egeria/DemoCode/My_Profile/ShowCommentsScreen.py index 9536940d..c27df8d7 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/ShowCommentsScreen.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/ShowCommentsScreen.py @@ -86,7 +86,7 @@ def load_comments(self, element_guid: str) -> None: comments_list = exec_report_spec( format_set_name="Comment-by-Element", output_format="DICT", - params={"element_guid": element_guid}, + params={"element_guid": element_guid, "graph_query_depth": 0}, # comment properties only view_server=self.view_server, view_url=self.platform_url, user=self.user_name, diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/ViewSubscriptionsScreen.py b/my_egeria/my_egeria/DemoCode/My_Profile/ViewSubscriptionsScreen.py index 35583493..0b12122a 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/ViewSubscriptionsScreen.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/ViewSubscriptionsScreen.py @@ -61,6 +61,7 @@ def get_my_subscriptions(self) -> list[tuple[str, str, str, str]]: search_string="*", metadata_element_type_name="DigitalSubscription", output_format="JSON", + graph_query_depth=0, # only header/properties are used ) except PyegeriaException as e: print_basic_exception(e) diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/bookmarks_handler.py b/my_egeria/my_egeria/DemoCode/My_Profile/bookmarks_handler.py index e9bae699..34a1190c 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/bookmarks_handler.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/bookmarks_handler.py @@ -49,7 +49,7 @@ def _bookmarks_client(self) -> Egeria: def _find_bookmarks_collection(self, client: Egeria) -> str | None: """GUID of the user's bookmarks collection, or None if it doesn't exist yet.""" qualified_name = bookmarks_qualified_name(self.user_name) - response = client.get_collections_by_name(name=qualified_name, output_format="JSON") + response = client.get_collections_by_name(name=qualified_name, output_format="JSON", graph_query_depth=0) for element in response if isinstance(response, list) else []: summary = element_summary(element) if summary.get("qualified_name") == qualified_name and summary.get("guid"): @@ -99,7 +99,9 @@ def _get_or_create_bookmarks_collection(self, client: Egeria) -> str: return guid def _bookmark_rows(self, client: Egeria, collection_guid: str) -> list[tuple[str, str, str]]: - response = client.get_collection_members(collection_guid=collection_guid, output_format="JSON") + # Depth 0: rows show name/type/guid only (a 30s timeout at the default depth 3 vs ~0.3s). + response = client.get_collection_members(collection_guid=collection_guid, output_format="JSON", + graph_query_depth=0) rows = [] for element in response if isinstance(response, list) else []: summary = element_summary(element) diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/my_profile_app.py b/my_egeria/my_egeria/DemoCode/My_Profile/my_profile_app.py index dc019d49..17fea454 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/my_profile_app.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/my_profile_app.py @@ -268,9 +268,13 @@ async def _load_profile_and_populate(self) -> bool: try: self.my_profile_inst = MyProfile(self.view_server, self.platform_url, self.user_name, self.user_password) self.my_profile_inst.create_egeria_bearer_token(self.user_name, self.user_password) - self.my_profile_data = await self.my_profile_inst._async_get_my_profile( - report_spec="My-User-MD", - output_format="DICT", + # Fetch the profile once and format it locally for each view (My-User-MD here, + # User-Identities in _process_profile_data) instead of fetching it per view. + self.my_profile_raw = await self.my_profile_inst._async_get_my_profile(output_format="JSON") + self.my_profile_data = ( + self.my_profile_inst._generate_my_profile_output( + self.my_profile_raw, "My", "MyProfile", "DICT", "My-User-MD") + if isinstance(self.my_profile_raw, dict) else self.my_profile_raw ) self.log(f"retrieve profile result: {self.my_profile_data}") except PyegeriaException as e: @@ -342,10 +346,11 @@ def _process_profile_data(self, profile_struct: list[dict]) -> None: # User Identities try: - self.user_identities = self.my_profile_inst.get_my_profile( - report_spec="User-Identities", - params={"graph_query_depth": 0}, - output_format="DICT", + raw = getattr(self, "my_profile_raw", None) + self.user_identities = ( + self.my_profile_inst._generate_my_profile_output(raw, "My", "MyProfile", "DICT", "User-Identities") + if isinstance(raw, dict) + else self.my_profile_inst.get_my_profile(report_spec="User-Identities", output_format="DICT") ) self.log(f"User-Identities: {self.user_identities}, type: {type(self.user_identities)}") except PyegeriaException as e: @@ -356,7 +361,7 @@ def _process_profile_data(self, profile_struct: list[dict]) -> None: try: self.my_todos_data = self.my_profile_inst.get_my_to_dos( report_spec="My-User-ToDos", - params={"graph_query_depth": 0}, + graph_query_depth=0, # the to-do table shows properties only output_format="DICT", ) self.log(f"My To-Dos: {self.my_todos_data}, type: {type(self.my_todos_data)}") @@ -419,7 +424,8 @@ def _load_my_collections(self) -> list[dict[str, str]]: eclient = Egeria(view_server=self.view_server, platform_url=self.platform_url, user_id=self.user_name, user_pwd=self.user_password) eclient.create_egeria_bearer_token(self.user_name, self.user_password) - response = eclient.find_collections(search_string="*", output_format="JSON") + # Depth 0: only header/properties are summarised (~70s at the default depth 3 vs <1s). + response = eclient.find_collections(search_string="*", output_format="JSON", graph_query_depth=0) except PyegeriaException as e: self.log(f"Error retrieving My Collections: {e!s}") return [] diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/shop_for_data_handler.py b/my_egeria/my_egeria/DemoCode/My_Profile/shop_for_data_handler.py index 14d54922..e86d9048 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/shop_for_data_handler.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/shop_for_data_handler.py @@ -131,6 +131,31 @@ def _extract_report_data(self, raw_data: Any) -> list[dict[str, Any]]: return [item for item in raw_data if isinstance(item, dict)] return [] + def _fetch_one(self, report_spec: str, qualified_name: str, graph_query_depth: int = 1) -> dict[str, Any] | None: + """Fetch one element's row at the given depth, matched on its exact qualified name. + + The list tables load at graph_query_depth=0 (fast, properties only); detail views + that show related elements (glossary folders, collection members) fetch just the + selected element at depth 1 instead. + """ + try: + result = exec_report_spec( + format_set_name=report_spec, + output_format="DICT", + params={"search_string": qualified_name, "graph_query_depth": graph_query_depth}, + view_server=self.view_server, + view_url=self.platform_url, + user=self.user_name, + user_pass=self.user_password, + ) + except Exception as e: + self.app.log(f"Error retrieving {report_spec} details for {qualified_name}: {e!s}") + return None + for row in self._extract_report_data(result): + if row.get("Qualified Name") == qualified_name: + return row + return None + async def handle_shop_for_data_option(self) -> Any: """Push new Screen, Show Glossaries, Digital Product Catalogs, Data Dictionaries and Business Domains, allow the user to select from one of the 4 categories and use that selection to @@ -575,7 +600,7 @@ def build_domain_details(self, target_qualified_name: str, target_type__name: st output_format="DICT", params={"search_string": self.domain_qualified_name, "filter_string": self.domain_qualified_name, - "graph_query_depth": 0 + "graph_query_depth": 1 }, view_server=self.view_server, view_url=self.platform_url, @@ -655,7 +680,7 @@ def build_catalog_details(self, target_qualified_name: str, target_display_name: output_format="DICT", params={"search_string": self.catalog_qualified_name, "filter_string": self.catalog_qualified_name, - "graph_query_depth": 0}, + "graph_query_depth": 1}, view_server=self.view_server, view_url=self.platform_url, user=self.user_name, @@ -731,6 +756,7 @@ def build_catalog_details(self, target_qualified_name: str, target_display_name: search_string=membership_qname, start_from=0, page_size=1, + graph_query_depth=0, # only the GUID of the first row is used output_format="DICT", ) self.app.log(f"Dataset metadata retrieved: {data_set_metadata}") @@ -772,7 +798,9 @@ def build_glossary_details(self, target_qualified_name: str, target_display_name glossary_tree: Tree = Tree(label=self.glossary_display_name, id="glossary_details_tree") - for glossary_instance in self.glossary_data_extract: + # Folders are related elements: absent from the depth-0 list, so fetch this glossary at depth 1. + selected = self._fetch_one("Glossaries", target_qualified_name) + for glossary_instance in ([selected] if selected else self.glossary_data_extract): if glossary_instance.get("Qualified Name") == target_qualified_name: self.glossary_folders = glossary_instance.get("Folders") or None self.app.log(f"glossary_folders: {self.glossary_folders}") @@ -840,7 +868,9 @@ def build_root_collection_details(self, target_qualified_name: str, target_displ self.root_collection_qualified_name = target_qualified_name collection_branch = member_tree.root.add(self.root_collection_qualified_name, expand=True) self.app.log(f"self_collections: {self.collections}") - collection = self.collections[0] if isinstance(self.collections, list) and len(self.collections) > 0 else {} + # Containing Members are related elements: absent from the depth-0 list, so fetch the + # selected collection at depth 1 (this also works for any row, not just the first). + collection = self._fetch_one("BasicCollections", target_qualified_name) or {} self.app.log(f"collection: {collection}") if target_qualified_name == collection.get("Qualified Name"): root_collection_contains: str = collection.get("Containing Members") or "" @@ -1155,6 +1185,7 @@ async def request_to_sample_data_source( search_string=element_qname, start_from=0, page_size=1, + graph_query_depth=0, # only the GUID of the first row is used output_format="DICT", ) if (not data_set_metadata or data_set_metadata == "No elements found") and element_name: @@ -1162,6 +1193,7 @@ async def request_to_sample_data_source( search_string=element_name, start_from=0, page_size=1, + graph_query_depth=0, # only the GUID of the first row is used output_format="DICT", ) if isinstance(data_set_metadata, list) and len(data_set_metadata) > 0 and data_set_metadata != "No elements found": diff --git a/my_egeria/my_egeria/DemoCode/My_Profile/team_roles_handler.py b/my_egeria/my_egeria/DemoCode/My_Profile/team_roles_handler.py index ad90ea20..0b050795 100644 --- a/my_egeria/my_egeria/DemoCode/My_Profile/team_roles_handler.py +++ b/my_egeria/my_egeria/DemoCode/My_Profile/team_roles_handler.py @@ -202,7 +202,8 @@ def display_glossary_term_details(self, term: str) -> int: self.term_details = exec_report_spec( format_set_name="Glossary-Terms", output_format="JSON", - params={"search_string": self.target_term, "filter_string": self.target_term}, + params={"search_string": self.target_term, "filter_string": self.target_term, + "graph_query_depth": 0}, # term properties only view_server=self.view_server, view_url=self.platform_url, user=self.user_name, diff --git a/my_egeria/my_egeria/README.md b/my_egeria/my_egeria/README.md index 5bf47d2b..1288dffa 100644 --- a/my_egeria/my_egeria/README.md +++ b/my_egeria/my_egeria/README.md @@ -17,7 +17,7 @@ The `my-egeria` Textual TUI application's package root — see the parent | `styles/` | Textual CSS. | | `tests/` | Tests for this app. | | `error_popup_app.py`, `startup_check.py` | Startup/error-handling helpers. | -| `serve.py` | Browser-mode serving (`textual serve`) — see `serve_my_egeria`/`serve_my_profile` entry points in the root `pyproject.toml`. | +| `serve.py` | Browser-mode serving via the `textual-serve` library — see the `serve_my_egeria`/`serve_my_profile` entry points in the root `pyproject.toml`. | | `DemoCode/` | Standalone demo scripts and experimental/deprecated code, not part of the main app (own subfolders per demo topic — Data Products, Journals, My Profile, Report Specs, Technology Type, plus `Deprecated/` and `Experimental Code/`). | `DemoCode/` is a scratch/demo area, not maintained to the same standard as diff --git a/my_egeria/my_egeria/serve.py b/my_egeria/my_egeria/serve.py index 78dad6de..9d1c6a3e 100644 --- a/my_egeria/my_egeria/serve.py +++ b/my_egeria/my_egeria/serve.py @@ -2,34 +2,53 @@ SPDX-License-Identifier: Apache-2.0 Copyright Contributors to the ODPi Egeria project. -Entry points for running my_egeria Textual apps via `textual serve` (browser mode). -Host and port are controlled by environment variables: - MY_EGERIA_HOST (default: 0.0.0.0) -- shared by all served apps - MY_PROFILE_PORT (default: 8020) -- my_profile demo app - MY_EGERIA_PORT (default: 8021) -- main MyEgeria app +Entry points for running the my_egeria Textual apps in a browser. + +Local browser mode (textual-serve): each browser connection gets its own app process. + serve_my_egeria / serve_my_profile + MY_EGERIA_HOST (default: 0.0.0.0) -- shared by all served apps + MY_EGERIA_PORT (default: 8021) -- main MyEgeria app + MY_PROFILE_PORT (default: 8020) -- my_profile demo app + MY_EGERIA_PUBLIC_URL / MY_PROFILE_PUBLIC_URL (optional) -- the URL browsers use, + when it differs from host:port (e.g. behind a reverse proxy); + MY_EGERIA_PUBLIC_URL applies to either app if the app's own isn't set + +The apps run with the same Python interpreter as this entry point, so this works +wherever pyegeria is installed (no `textual` CLI from textual-dev needed). """ -import importlib.util import os -import subprocess import sys +APPS = { + # name: (module run with `python -m`, port env var, default port, public URL env var) + "My Egeria": ("my_egeria.main", "MY_EGERIA_PORT", "8021", "MY_EGERIA_PUBLIC_URL"), + "My Profile": ("my_egeria.DemoCode.My_Profile.my_profile_app", "MY_PROFILE_PORT", "8020", "MY_PROFILE_PUBLIC_URL"), +} + + +def _command(module: str) -> str: + return f'"{sys.executable}" -m {module}' -def _serve(app_module: str, port_env: str, default_port: str) -> None: - spec = importlib.util.find_spec(app_module) - if spec is None or spec.origin is None: - print(f"Cannot locate module {app_module}", file=sys.stderr) - sys.exit(1) - host = os.getenv("MY_EGERIA_HOST", "0.0.0.0") - port = os.getenv(port_env, default_port) - subprocess.run( - ["textual", "serve", "--host", host, "--port", port, spec.origin], - check=False, - ) + +def _serve(name: str) -> None: + from textual_serve.server import Server + + module, port_env, default_port, public_url_env = APPS[name] + Server( + _command(module), + host=os.getenv("MY_EGERIA_HOST", "0.0.0.0"), + port=int(os.getenv(port_env, default_port)), + title=name, + # MY_EGERIA_PUBLIC_URL is what egeria-workspaces' my-profile container sets + # (one app per container), so honour it for either app. + public_url=os.getenv(public_url_env) or os.getenv("MY_EGERIA_PUBLIC_URL") or None, + ).serve() def serve_my_profile() -> None: - _serve("my_egeria.DemoCode.My_Profile.my_profile_app", "MY_PROFILE_PORT", "8020") + _serve("My Profile") def serve_my_egeria() -> None: - _serve("my_egeria.my_egeria_app", "MY_EGERIA_PORT", "8021") + _serve("My Egeria") + diff --git a/my_egeria/my_egeria/startup_check.py b/my_egeria/my_egeria/startup_check.py index 9dd3609e..771aeaa6 100644 --- a/my_egeria/my_egeria/startup_check.py +++ b/my_egeria/my_egeria/startup_check.py @@ -15,6 +15,11 @@ os.environ.setdefault("EGERIA_USER_PASSWORD", "secret") os.environ.setdefault("EGERIA_VIEW_SERVER", "qs-view-server") os.environ.setdefault("EGERIA_PLATFORM_URL", "https://localhost:9443") +# config.REQUIRED_ENVS still uses the older names; derive them from the documented +# ones (and their defaults) so the app starts as the README describes. An explicit +# EGERIA_SERVER / EGERIA_BASE_URL still wins. +os.environ.setdefault("EGERIA_SERVER", os.environ["EGERIA_VIEW_SERVER"]) +os.environ.setdefault("EGERIA_BASE_URL", os.environ["EGERIA_PLATFORM_URL"]) from typing import Tuple from my_egeria.config import ( diff --git a/my_egeria/my_egeria/tests/test_startup_check.py b/my_egeria/my_egeria/tests/test_startup_check.py index 74496750..1500c92d 100644 --- a/my_egeria/my_egeria/tests/test_startup_check.py +++ b/my_egeria/my_egeria/tests/test_startup_check.py @@ -27,3 +27,12 @@ def test_check_connection_no_pyegeria(monkeypatch): ok, msg = check_connection() assert not ok assert "pyegeria import failed" in msg + + +def test_validate_envs_derives_old_names_from_documented_ones(): + # The README documents EGERIA_VIEW_SERVER / EGERIA_PLATFORM_URL (with defaults); + # importing startup_check fills in the EGERIA_SERVER / EGERIA_BASE_URL it validates. + assert os.environ.get("EGERIA_SERVER") + assert os.environ.get("EGERIA_BASE_URL") + ok, _ = validate_envs() + assert ok diff --git a/my_egeria/pyproject.toml b/my_egeria/pyproject.toml index 2aa0fe1b..8fced501 100644 --- a/my_egeria/pyproject.toml +++ b/my_egeria/pyproject.toml @@ -34,12 +34,6 @@ include = ["my_egeria", "my_egeria.*"] [project.scripts] # Terminal mode my-egeria = "my_egeria.main:main" -# Browser mode (textual serve); env: MY_EGERIA_HOST, MY_EGERIA_PORT, MY_PROFILE_PORT +# Local browser mode (textual-serve); env: MY_EGERIA_HOST, MY_EGERIA_PORT, MY_PROFILE_PORT serve-my-egeria = "my_egeria.serve:serve_my_egeria" -serve-my-profile = "my_egeria.serve:serve_my_profile" - -[app.my-egeria] -command = "serve_my_egeria" - -[app.my-profile] -command = "python my_egeria.DemoCode.My_Profile.my_profile_app:main" \ No newline at end of file +serve-my-profile = "my_egeria.serve:serve_my_profile" \ No newline at end of file diff --git a/pyegeria/config/__init__.py b/pyegeria/config/__init__.py new file mode 100644 index 00000000..c136d40c --- /dev/null +++ b/pyegeria/config/__init__.py @@ -0,0 +1,2 @@ +"""Package marker: ships this directory now that wheel package discovery +doesn't pick up namespace packages (see [tool.setuptools.packages.find]).""" diff --git a/pyegeria/view/format_set_executor.py b/pyegeria/view/format_set_executor.py index 02f955a2..5a85c345 100644 --- a/pyegeria/view/format_set_executor.py +++ b/pyegeria/view/format_set_executor.py @@ -361,6 +361,28 @@ def _merge_signature_params(func: Any, params: Dict[str, Any], call_params: Dict return merged +# Request options every find/get method understands but report specs don't list in +# their required/optional params. exec_report_spec only copies declared params, so +# without this a caller's graph_query_depth was silently dropped and every call ran +# at the SDK default depth of 3 -- the dominant cost of list calls (ISSUE-15). +_PASS_THROUGH_REQUEST_OPTIONS = ("graph_query_depth",) + + +def _add_request_options(func: Any, params: Dict[str, Any], call_params: Dict[str, Any]) -> Dict[str, Any]: + """Forward _PASS_THROUGH_REQUEST_OPTIONS from the caller's params when the method accepts them.""" + try: + sig = inspect.signature(func) + except Exception: + return call_params + accepts_kwargs = any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()) + merged = dict(call_params) + for key in _PASS_THROUGH_REQUEST_OPTIONS: + value = (params or {}).get(key) + if value is not None and key not in merged and (key in sig.parameters or accepts_kwargs): + merged[key] = value + return merged + + def _validate_report_spec_params(report_spec, params): """Validate that required parameters are present in the provided params dictionary.""" missing_params = [param for param in report_spec.required_params if param not in params] @@ -851,6 +873,7 @@ def exec_report_spec( f"Method '{method_name}' not found in client class '{client_class.__name__}'." ) + call_params = _add_request_options(func, params, call_params) result = func(**call_params) if not result or result == NO_ELEMENTS_FOUND: diff --git a/pyproject.toml b/pyproject.toml index 6f36bf9e..53d88b79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -138,7 +138,7 @@ dependencies = [ # my_egeria TUI apps — terminal mode my_egeria = "my_egeria.main:main" my_profile = "my_egeria.DemoCode.My_Profile.my_profile_app:main" - # my_egeria TUI apps — browser mode (textual serve); env: MY_EGERIA_HOST, MY_EGERIA_PORT, MY_PROFILE_PORT + # my_egeria TUI apps — local browser mode (textual-serve); env: MY_EGERIA_HOST, MY_EGERIA_PORT, MY_PROFILE_PORT serve_my_egeria = "my_egeria.serve:serve_my_egeria" serve_my_profile = "my_egeria.serve:serve_my_profile" @@ -213,8 +213,16 @@ requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] +# my_egeria's real package lives at my_egeria/my_egeria (my_egeria/ is a uv workspace +# member). Searching from both roots installs it as the top-level `my_egeria` package, +# which its console scripts and its own `from my_egeria.` imports require; +# searching only from "." shipped it as my_egeria/my_egeria/..., so `my_egeria`, +# `my_profile`, `serve_my_egeria` and `serve_my_profile` failed in every PyPI install. +# namespaces = false stops "." also picking up the outer my_egeria/ directory. +where = [".", "my_egeria"] include = ["pyegeria", "pyegeria.*", "commands", "commands.*", "md_processing", "md_processing.*", "my_egeria", "my_egeria.*"] exclude = ["tests", "config"] +namespaces = false [tool.setuptools.package-data] "md_processing" = [ diff --git a/tests/micro-tests/my_profile/test_bookmarks_handler.py b/tests/micro-tests/my_profile/test_bookmarks_handler.py index 18ff678a..b016098e 100644 --- a/tests/micro-tests/my_profile/test_bookmarks_handler.py +++ b/tests/micro-tests/my_profile/test_bookmarks_handler.py @@ -68,7 +68,8 @@ def test_list_returns_member_rows(self, client): {"relatedElement": _element("asset-2", "Churn Model", "Asset")}, ] rows = DummyApp().list_my_bookmarks() - client.get_collection_members.assert_called_once_with(collection_guid="bm-coll-guid", output_format="JSON") + client.get_collection_members.assert_called_once_with(collection_guid="bm-coll-guid", output_format="JSON", + graph_query_depth=0) assert rows == [("Sales Data", "DataSet", "asset-1"), ("Churn Model", "Asset", "asset-2")] def test_list_ignores_same_name_collection_with_other_qualified_name(self, client): diff --git a/tests/micro-tests/test_exec_report_spec_graph_query_depth.py b/tests/micro-tests/test_exec_report_spec_graph_query_depth.py new file mode 100644 index 00000000..ee06d8d2 --- /dev/null +++ b/tests/micro-tests/test_exec_report_spec_graph_query_depth.py @@ -0,0 +1,70 @@ +""" +exec_report_spec only copies a report spec's declared required/optional params into +the call, so a caller's graph_query_depth used to be silently dropped and every call +ran at the SDK default depth of 3 (live: the "Glossaries" list timed out at 90s at +depth 3 vs 0.3s at depth 0). It is now forwarded when the target method accepts it. +""" +import pytest + +import pyegeria.view.format_set_executor as fse + + +class _FakeClient: + calls: list = [] + + def __init__(self, *args, **kwargs): + pass + + def create_egeria_bearer_token(self, *args, **kwargs): + return "token" + + def set_bearer_token(self, token): + pass + + def close_session(self): + pass + + def find_glossaries(self, search_string="*", graph_query_depth: int = 3, **kwargs): + _FakeClient.calls.append({"search_string": search_string, "graph_query_depth": graph_query_depth, **kwargs}) + return [{"guid": "g1"}] + + def no_depth_method(self, search_string="*", output_format="DICT", report_spec=None): + _FakeClient.calls.append({"search_string": search_string}) + return [{"guid": "g1"}] + + +@pytest.fixture(autouse=True) +def _fake_client(monkeypatch): + _FakeClient.calls = [] + monkeypatch.setattr(fse, "_resolve_client_and_method", + lambda func_decl: (_FakeClient, func_decl.split(".")[-1])) + + +def _run(params): + # "Glossaries" is a real registered spec (GlossaryManager.find_glossaries) that does + # not list graph_query_depth in its required/optional params. + return fse.exec_report_spec("Glossaries", output_format="DICT", params=params, + view_server="v", view_url="https://x", user="u", user_pass="p") + + +@pytest.mark.parametrize("depth", [0, 1]) +def test_graph_query_depth_reaches_the_method(depth): + result = _run({"search_string": "*", "graph_query_depth": depth}) + assert result["kind"] == "json" + assert _FakeClient.calls[0]["graph_query_depth"] == depth + + +def test_default_depth_unchanged_when_not_given(): + _run({"search_string": "*"}) + assert _FakeClient.calls[0]["graph_query_depth"] == 3 + + +def test_other_undeclared_params_still_not_forwarded(): + _run({"search_string": "*", "graph_query_depth": 0, "not_a_spec_param": "x"}) + assert "not_a_spec_param" not in _FakeClient.calls[0] + + +def test_not_forwarded_to_a_method_that_cannot_take_it(): + params = {"search_string": "*", "graph_query_depth": 0} + merged = fse._add_request_options(_FakeClient().no_depth_method, params, {"search_string": "*"}) + assert "graph_query_depth" not in merged