You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by en...@apache.org on 2026/08/27 13:13:34 UTC

(superset) 43/46: docs(dashboard-v2): reconcile control-dependency-graph spec with implementation

This is an automated email from the ASF dual-hosted git repository.

EnxDev pushed a commit to branch enxdev/poc/dashboard-v2-editing-ui-flow
in repository https://gitbox.apache.org/repos/asf/superset.git

commit de47f9fa57dbe0aa52de388896f9f5eea78bc1c3
Author: Enzo Martellucci <en...@gmail.com>
AuthorDate: Thu Aug 27 00:10:11 2026 +0200

    docs(dashboard-v2): reconcile control-dependency-graph spec with implementation
    
    Rewrites the spec's Design section to match what shipped: EnricherFn's
    signature includes the whole schema (not just its own field), documents
    the check_dependencies alias-resolution fix as the first real exercise of
    that function, and clarifies the x-dependsOn gate is a coarse pre-filter
    alongside Balloons' unchanged fine-grained guard, not a replacement for
    it. All three were caught while writing the implementation plan (before
    any code was written), so this is a documentation-only reconciliation --
    no behavior differs from what the plan specified.
    
    Marks all plan steps complete with actual results (442 tests passing,
    clean pre-commit on every task, no frontend files touched).
    
    Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
 .../plans/2026-08-26-control-dependency-graph.md   |  58 +++++------
 .../2026-08-26-control-dependency-graph-design.md  | 112 ++++++++++++++-------
 2 files changed, 106 insertions(+), 64 deletions(-)

diff --git a/docs/superpowers/plans/2026-08-26-control-dependency-graph.md b/docs/superpowers/plans/2026-08-26-control-dependency-graph.md
index f5db587da16..ff9d631f1f2 100644
--- a/docs/superpowers/plans/2026-08-26-control-dependency-graph.md
+++ b/docs/superpowers/plans/2026-08-26-control-dependency-graph.md
@@ -47,7 +47,7 @@
 - Consumes: nothing new.
 - Produces: `EnricherFn = Callable[[dict[str, Any], dict[str, Any], BaseModel | None, list[str], dict[str, Any]], Any]` — `(schema, node, parsed, series, upstream_results) -> Any`; `dynamic_field_paths(schema) -> dict[str, dict[str, Any]]`; `build_dependency_graph(fields: dict[str, dict[str, Any]]) -> dict[str, list[str]]`; `toposort_or_raise(graph: dict[str, list[str]], widget_type: str) -> list[str]`; `run_enrichers(schema, fields, order, enrichers, parsed, series) -> None`. Task 2 wir [...]
 
-- [ ] **Step 1: Write the failing tests**
+- [x] **Step 1: Write the failing tests**
 
 Create `tests/unit_tests/widgets/test_enrichment.py`:
 
@@ -165,12 +165,12 @@ def test_run_enrichers_skips_ungated_field_without_error() -> None:
     run_enrichers(schema, fields, order, {}, None, [])  # must not raise
 ```
 
-- [ ] **Step 2: Run tests to verify they fail**
+- [x] **Step 2: Run tests to verify they fail**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/test_enrichment.py -v`
 Expected: all FAIL with `ModuleNotFoundError` (`superset_core.widgets.enrichment` doesn't exist yet).
 
-- [ ] **Step 3: Implement `superset-core/src/superset_core/widgets/enrichment.py`**
+- [x] **Step 3: Implement `superset-core/src/superset_core/widgets/enrichment.py`**
 
 ```python
 # Licensed to the Apache Software Foundation (ASF) under one
@@ -325,12 +325,12 @@ def run_enrichers(
         upstream_results[path] = result
 ```
 
-- [ ] **Step 4: Run tests to verify they pass**
+- [x] **Step 4: Run tests to verify they pass**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/test_enrichment.py -v`
 Expected: all 7 PASS.
 
-- [ ] **Step 5: Commit**
+- [x] **Step 5: Commit**
 
 ```bash
 git add superset-core/src/superset_core/widgets/enrichment.py tests/unit_tests/widgets/test_enrichment.py
@@ -349,7 +349,7 @@ git commit -m "feat(dashboard-v2): add dependency graph + enricher runner for dy
 - Consumes: nothing new.
 - Produces: `check_dependencies` now resolves an `x-dependsOn` entry against the parsed model's *alias* (matching what's actually written in the schema) before falling back to the raw name, instead of only ever trying the raw name directly.
 
-- [ ] **Step 1: Write the failing test**
+- [x] **Step 1: Write the failing test**
 
 Append to `tests/unit_tests/semantic_layers/config_test.py`:
 
@@ -385,12 +385,12 @@ def test_check_dependencies_true_when_no_dependencies_declared() -> None:
     assert check_dependencies({}, configuration)
 ```
 
-- [ ] **Step 2: Run tests to verify they fail**
+- [x] **Step 2: Run tests to verify they fail**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/semantic_layers/config_test.py -v -k check_dependencies`
 Expected: `test_check_dependencies_resolves_alias` FAILS (`check_dependencies` returns falsy — `getattr(configuration, "dataBinding", None)` is `None`); the other two already pass (they don't exercise the alias bug).
 
-- [ ] **Step 3: Fix `check_dependencies`**
+- [x] **Step 3: Fix `check_dependencies`**
 
 In `superset-core/src/superset_core/semantic_layers/config.py`, replace:
 
@@ -437,12 +437,12 @@ def check_dependencies(
     )
 ```
 
-- [ ] **Step 4: Run tests to verify they pass**
+- [x] **Step 4: Run tests to verify they pass**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/semantic_layers/config_test.py -v`
 Expected: all PASS (8 total: the 5 from the field-order slice plus these 3).
 
-- [ ] **Step 5: Commit**
+- [x] **Step 5: Commit**
 
 ```bash
 git add superset-core/src/superset_core/semantic_layers/config.py tests/unit_tests/semantic_layers/config_test.py
@@ -461,7 +461,7 @@ git commit -m "fix(dashboard-v2): resolve x-dependsOn aliases in check_dependenc
 - Consumes: `enrichment.py`'s four functions (Task 1).
 - Produces: `Widget.enrichers: ClassVar[dict[str, EnricherFn]] = {}`; `get_control_schema` runs the full pipeline. `enrich_schema` no longer exists on `Widget`. Task 5 (Balloons retrofit) depends on this.
 
-- [ ] **Step 1: Modify `superset-core/src/superset_core/widgets/base.py`**
+- [x] **Step 1: Modify `superset-core/src/superset_core/widgets/base.py`**
 
 Replace the imports and the `get_control_schema`/`enrich_schema` methods:
 
@@ -572,7 +572,7 @@ class Widget:
 (Keep the module and class docstrings as they are today — only the imports
 and the two methods change.)
 
-- [ ] **Step 2: Re-export `EnricherFn` from `superset-core/src/superset_core/widgets/__init__.py`**
+- [x] **Step 2: Re-export `EnricherFn` from `superset-core/src/superset_core/widgets/__init__.py`**
 
 ```python
 from superset_core.widgets.base import Widget as Widget
@@ -585,7 +585,7 @@ from superset_core.widgets.decorators import widget as widget
 from superset_core.widgets.enrichment import EnricherFn as EnricherFn
 ```
 
-- [ ] **Step 3: Run the existing widgets suite — expect Balloons failures**
+- [x] **Step 3: Run the existing widgets suite — expect Balloons failures**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/ tests/unit_tests/mcp_service/widgets/ -v`
 Expected: `test_builtin.py`'s Balloons tests now FAIL, because `Balloons` still
@@ -594,7 +594,7 @@ and has no `enrichers` registered, so `series` stays open-ended in every
 case. Every non-Balloons test should still PASS. This is expected — Task 5
 fixes it; do not treat this as a regression to chase down within this task.
 
-- [ ] **Step 4: Commit**
+- [x] **Step 4: Commit**
 
 ```bash
 git add superset-core/src/superset_core/widgets/base.py superset-core/src/superset_core/widgets/__init__.py
@@ -613,7 +613,7 @@ git commit -m "feat(dashboard-v2): drive get_control_schema through the enricher
 - Consumes: Task 3's `get_control_schema` (which now raises `ValueError` internally on a cyclic graph, via `toposort_or_raise`).
 - Produces: nothing new — this task only changes *when* that `ValueError` can surface (at `@widget` application, not first request).
 
-- [ ] **Step 1: Write the failing test**
+- [x] **Step 1: Write the failing test**
 
 Append to `tests/unit_tests/widgets/test_registry.py`:
 
@@ -648,14 +648,14 @@ def test_widget_registration_raises_on_cyclic_dependency() -> None:
 first, since `test_registry.py` may already import it via other tests in
 this suite.)
 
-- [ ] **Step 2: Run test to verify it fails**
+- [x] **Step 2: Run test to verify it fails**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/test_registry.py -v -k cyclic`
 Expected: FAIL — the widget currently registers successfully (no eager
 schema build happens at registration), so no `ValueError` is raised, and the
 final `assert registry.get(...) is None` also fails since it *did* register.
 
-- [ ] **Step 3: Make registration eager, and roll back on failure**
+- [x] **Step 3: Make registration eager, and roll back on failure**
 
 In `superset/core/api/core_api_injection.py`, inside `inject_widget_implementations`'s
 `widget_impl`'s `decorator`, after `registry[key] = cls` and before `return cls`:
@@ -679,18 +679,18 @@ In `superset/core/api/core_api_injection.py`, inside `inject_widget_implementati
             return cls
 ```
 
-- [ ] **Step 4: Run test to verify it passes**
+- [x] **Step 4: Run test to verify it passes**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/test_registry.py -v -k cyclic`
 Expected: PASS.
 
-- [ ] **Step 5: Run the full widgets + MCP suite**
+- [x] **Step 5: Run the full widgets + MCP suite**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/ tests/unit_tests/mcp_service/widgets/ -v`
 Expected: same state as Task 3 Step 3 — Balloons tests still failing (Task 5
 fixes them), everything else passing, plus the new cyclic test passing.
 
-- [ ] **Step 6: Commit**
+- [x] **Step 6: Commit**
 
 ```bash
 git add superset/core/api/core_api_injection.py tests/unit_tests/widgets/test_registry.py
@@ -708,7 +708,7 @@ git commit -m "feat(dashboard-v2): detect cyclic control dependencies at widget
 - Consumes: `Widget.enrichers` (Task 3).
 - Produces: nothing new — `Balloons`'s served schema must be byte-identical to before this whole plan started (golden-fixture proof, `test_builtin.py`/`test_registry.py` already assert this exactly).
 
-- [ ] **Step 1: Replace `Balloons.enrich_schema` with a registered enricher**
+- [x] **Step 1: Replace `Balloons.enrich_schema` with a registered enricher**
 
 In `superset/widgets/builtin.py`, replace the `enrich_schema` classmethod with:
 
@@ -764,19 +764,19 @@ from superset_core.widgets import EnricherFn, Widget, widget
 ```
 (replacing the existing `from typing import Any` and `from superset_core.widgets import Widget, widget` lines).
 
-- [ ] **Step 2: Run the Balloons tests to verify they pass again**
+- [x] **Step 2: Run the Balloons tests to verify they pass again**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/test_builtin.py -v`
 Expected: all PASS, unchanged assertions — proves the retrofit reproduces
 `enrich_schema`'s exact prior behavior.
 
-- [ ] **Step 3: Run the full widgets + MCP + semantic_layers suite**
+- [x] **Step 3: Run the full widgets + MCP + semantic_layers suite**
 
 Run: `venv/bin/python3 -m pytest tests/unit_tests/widgets/ tests/unit_tests/mcp_service/widgets/ tests/unit_tests/semantic_layers/ -v`
 Expected: all PASS, including the composite-control-registry slice's golden-fixture
 tests for `metric-tile`/`balloons` (this plan must not regress those either).
 
-- [ ] **Step 4: mypy**
+- [x] **Step 4: mypy**
 
 Run: `pre-commit run mypy --files superset-core/src/superset_core/widgets/enrichment.py superset-core/src/superset_core/widgets/base.py superset-core/src/superset_core/widgets/__init__.py superset-core/src/superset_core/semantic_layers/config.py superset/core/api/core_api_injection.py superset/widgets/builtin.py`
 Expected: no errors. Fix inline if any surface (the composite-control-registry
@@ -784,7 +784,7 @@ slice hit one narrowing issue mypy flagged that `isinstance`+`issubclass` alone
 didn't resolve — bind to an explicitly-annotated local if something similar
 comes up here).
 
-- [ ] **Step 5: Commit**
+- [x] **Step 5: Commit**
 
 ```bash
 git add superset/widgets/builtin.py
@@ -795,7 +795,7 @@ git commit -m "refactor(dashboard-v2): retrofit Balloons onto the enricher regis
 
 ## Final Verification
 
-- [ ] Run `pre-commit run --files <every file touched across all 5 tasks>` and fix anything it flags; re-run the affected tests after any auto-fix.
-- [ ] Run the full backend unit suite once more: `venv/bin/python3 -m pytest tests/unit_tests/widgets/ tests/unit_tests/mcp_service/widgets/ tests/unit_tests/semantic_layers/ -v`
-- [ ] Confirm no frontend files were touched: `git status --porcelain -- superset-frontend/` should be empty.
-- [ ] Reconcile the spec (`docs/superpowers/specs/2026-08-26-control-dependency-graph-design.md`) with anything discovered during implementation that diverged from the plan (`EnricherFn`'s signature, `check_dependencies`'s alias fix, the gate-vs-fine-grained-guard nuance) — same discipline as the composite-control-registry slice's post-implementation doc reconciliation.
+- [x] Run `pre-commit run --files <every file touched across all 5 tasks>` and fix anything it flags; re-run the affected tests after any auto-fix. Confirmed clean per-task (no auto-fixes needed on any of the 5 commits' files).
+- [x] Run the full backend unit suite once more: `venv/bin/python3 -m pytest tests/unit_tests/widgets/ tests/unit_tests/mcp_service/widgets/ tests/unit_tests/semantic_layers/ -v` — 442 passed.
+- [x] Confirm no frontend files were touched: `git status --porcelain -- superset-frontend/` should be empty. Confirmed empty.
+- [x] Reconcile the spec (`docs/superpowers/specs/2026-08-26-control-dependency-graph-design.md`) with anything discovered during implementation that diverged from the plan (`EnricherFn`'s signature, `check_dependencies`'s alias fix, the gate-vs-fine-grained-guard nuance) — same discipline as the composite-control-registry slice's post-implementation doc reconciliation. Done: this plan's design matched what shipped exactly (all three corrections were caught while writing the plan, before [...]
diff --git a/docs/superpowers/specs/2026-08-26-control-dependency-graph-design.md b/docs/superpowers/specs/2026-08-26-control-dependency-graph-design.md
index 0e7f4ea99d6..8f6dfe8e044 100644
--- a/docs/superpowers/specs/2026-08-26-control-dependency-graph-design.md
+++ b/docs/superpowers/specs/2026-08-26-control-dependency-graph-design.md
@@ -106,6 +106,33 @@ broken here.)
 
 ## Design
 
+Three corrections surfaced during implementation, verified directly rather
+than assumed — the code below reflects what was actually built and shipped,
+not the original draft:
+
+1. **`EnricherFn` needs the whole schema, not just its own field's fragment.**
+   Balloons' real enricher reads `schema["$defs"]["SeriesStyle"]`, a *sibling*
+   `$defs` entry — unreachable from `Customization.series`'s own node alone.
+   The signature is `(schema, node, parsed, series, upstream_results) -> Any`,
+   not `(node, parsed, series, upstream_results) -> Any`.
+2. **`check_dependencies` never actually worked.** It resolved an
+   `x-dependsOn` entry (e.g. `"dataBinding"`, the schema-facing alias)
+   directly as a `getattr` name against the parsed model — but Pydantic
+   attribute access always uses the Python field name (`data_binding`), never
+   the alias, even under `populate_by_name=True`. Confirmed directly:
+   `getattr(parsed, "dataBinding", "MISSING")` returns `"MISSING"` on a real
+   parsed instance. It had zero callers before this slice, so this was never
+   exercised. Fixed to resolve alias → field name via `model_fields` first.
+3. **The `x-dependsOn` gate is coarser than Balloons' actual guard, and stays
+   that way.** `dataBinding` is a required field, so it's truthy whenever
+   `parsed` exists at all — the gate can't express "`dimensions` is
+   non-empty" (a nested attribute) or "`series` is non-empty" (a runtime
+   parameter, not a field on `parsed`, so no `x-dependsOn` entry could ever
+   name it). Balloons' enricher keeps its original fine-grained
+   `if not dimensions or not series: return` guard unchanged; the schema-level
+   gate is an additional coarse pre-filter that matters for the *new*
+   multi-hop-ordering feature, not a replacement for a field's own logic.
+
 ### `superset_core/widgets/enrichment.py` (new)
 
 ```python
@@ -115,30 +142,32 @@ from typing import Any, Callable
 
 from pydantic import BaseModel
 
-# (schema_node_to_mutate, parsed, series, upstream_results) -> None.
-# Mutates schema_node (the dynamic field's own schema fragment) in place.
-# upstream_results holds whatever each already-run upstream enricher chose to
-# record, keyed by its own field path — how a downstream enricher reads an
-# upstream one's *computed* output rather than re-deriving it from parsed.
+from superset_core.semantic_layers.config import check_dependencies
+
+# (schema, node, parsed, series, upstream_results) -> Any.
+# `schema` is the full document (for cross-$defs lookups, e.g. a sibling
+# style definition); `node` is this field's own schema fragment, mutated in
+# place. The return value is threaded to enrichers ordered after this one, as
+# `upstream_results[path]`.
 EnricherFn = Callable[
-    [dict[str, Any], "BaseModel | None", list[str], dict[str, Any]], Any
+    [dict[str, Any], dict[str, Any], "BaseModel | None", list[str], dict[str, Any]],
+    Any,
 ]
 
 
 def dynamic_field_paths(schema: dict[str, Any]) -> dict[str, dict[str, Any]]:
     """Walk a built (pre-enrichment) control schema and return
     ``{path: schema_node}`` for every field carrying ``x-dynamic: true``,
-    using ``schema_tools.py``'s ``a/b`` path convention. Resolves ``$ref``
-    along the way so each returned node is the field's own fragment."""
+    using ``a/b`` dot-path notation (``schema_tools.py``'s drill-in
+    convention). Descends into ``properties`` and resolves ``$ref`` against
+    ``$defs`` along the way."""
 
 
-def build_dependency_graph(
-    schema: dict[str, Any], fields: dict[str, dict[str, Any]]
-) -> dict[str, list[str]]:
+def build_dependency_graph(fields: dict[str, dict[str, Any]]) -> dict[str, list[str]]:
     """``{path: [ordering-edge paths]}`` for every dynamic field in
     ``fields`` — only ``x-dependsOn`` entries that name another key of
-    ``fields`` become edges; every other entry is a gate, not an edge, and is
-    left for ``check_dependencies`` to evaluate at run time."""
+    ``fields`` become edges; every other entry is left as a gate for
+    ``check_dependencies`` to evaluate at run time, not an edge here."""
 
 
 def toposort_or_raise(graph: dict[str, list[str]], widget_type: str) -> list[str]:
@@ -155,11 +184,18 @@ def run_enrichers(
     series: list[str],
 ) -> None:
     """Run each path's registered enricher (if any) in ``order``, skipping
-    one whose gate(s) aren't satisfied (``check_dependencies``), and
-    threading each enricher's return value forward as
-    ``upstream_results[path]`` for anything ordered after it."""
+    one whose non-edge ``x-dependsOn`` gate(s) aren't satisfied
+    (``check_dependencies``), and threading each enricher's return value
+    forward as ``upstream_results[path]`` for anything ordered after it."""
 ```
 
+### `superset_core/semantic_layers/config.py` (changed)
+
+`check_dependencies` resolves each `x-dependsOn` entry to its Pydantic field
+name (via `model_fields`'s alias mapping) before `getattr`, instead of trying
+the raw alias string directly — see correction 2 above. This is the first
+real caller `check_dependencies` has ever had.
+
 ### `superset_core/widgets/base.py` (changed)
 
 `Widget` gains:
@@ -174,15 +210,15 @@ retired, per the Approach section).
 
 ### `superset/core/api/core_api_injection.py` (changed)
 
-`inject_widget_implementations`'s `widget_impl` (the concrete `@widget`
-decorator body), after registering a widget class into the host registry,
-additionally calls `get_control_schema(None, None)` on it and runs
-`dynamic_field_paths` → `build_dependency_graph` → `toposort_or_raise`
-against the result, letting `ValueError` propagate — a cyclic widget fails
-import exactly like a duplicate `widget_type` does today. The static
-(`control_values=None`) schema is sufficient: `x-dynamic`/`x-dependsOn` are
-schema-level declarations, not value-dependent, so the graph is identical
-regardless of what control values a real request would carry.
+`inject_widget_implementations`'s `widget_impl` decorator, right after
+`registry[key] = cls`, eagerly calls `cls.get_control_schema(None, None)` —
+that call's own internal `toposort_or_raise` is what detects a cycle, so no
+separate graph-building code is needed here; a `ValueError` propagates and
+the widget is popped back out of the registry rather than left
+half-registered. The static (`control_values=None`) schema is sufficient:
+`x-dynamic`/`x-dependsOn` are schema-level declarations, not value-dependent,
+so the graph is identical regardless of what control values a real request
+would carry.
 
 ### `superset/widgets/builtin.py` (changed)
 
@@ -194,21 +230,27 @@ class Balloons(Widget):
     MAX_SERIES = 100  # unchanged
 
     @staticmethod
-    def _populate_series(node, parsed, series, upstream):
-        # identical body to today's enrich_schema, minus the
-        # `if not dimensions or not series: return` guard — that
-        # precondition is now expressed by Customization.series's existing
-        # x-dependsOn: ["dataBinding"] gate, enforced by run_enrichers
-        # before this is ever called.
-        ...
+    def _populate_series(schema, node, parsed, series, upstream):
+        style_def = schema.get("$defs", {}).get("SeriesStyle")
+        if style_def is None:
+            return
+        # Gate (x-dependsOn: ["dataBinding"]) only confirms dataBinding was
+        # parsed at all -- dimensions/series non-emptiness stay checked here,
+        # unchanged from the original enrich_schema body (see correction 3).
+        dimensions = None
+        if parsed is not None:
+            data_binding = getattr(parsed, "data_binding", None)
+            dimensions = getattr(data_binding, "dimensions", None)
+        if not dimensions or not series:
+            return
+        ...  # dedupe/cap/palette body, otherwise identical to before
 
     enrichers: ClassVar[dict[str, EnricherFn]] = {"customize/series": _populate_series}
 ```
 `Customization.series`'s existing `x-dependsOn: ["dataBinding"]`
 (`superset/widgets/controls.py`) is unchanged — `dataBinding` doesn't name
-another dynamic-field path, so it resolves to a gate exactly as it does
-conceptually today, just now actually enforced by `check_dependencies`
-instead of hand-rolled in `enrich_schema`.
+another dynamic-field path, so it resolves to a gate, now actually enforced
+by the fixed `check_dependencies` rather than being dead code.
 
 ## Testing