Repository navigation
fix(charts): resolve semantic-view datasource name and link in chart list - #43649
Conversation
Code Review Agent Run #0c4a2cActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #43649 +/- ##
=======================================
Coverage 79.24% 79.25%
=======================================
Files 2888 2888
Lines 166446 166438 -8
Branches 38529 38525 -4
=======================================
+ Hits 131908 131911 +3
+ Misses 32045 32035 -10
+ Partials 2493 2492 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The flagged issue is correct. The PR introduces a To resolve this, you should update the chart response schema to resolve the I have checked the PR comments and there are no other comments to address. Would you like me to implement the schema update for you? |
…list Charts built on a semantic view showed an empty Datasource cell in the Charts list and `datasource_url` / `datasource_name_text` of null in the chart API, because `Slice`'s display helpers only resolved the datasource through the `SqlaTable` relationship. Add a type-guarded, view-only `Slice.semantic_view` relationship that mirrors `Slice.table`, and a display-only `_display_datasource()` resolver that dispatches on `datasource_type`. `datasource_url`, `datasource_name_text`, `datasource_link`, `datasource_edit_url` and `icons` read the resolved datasource through `getattr`, so an unresolved reference yields None for that chart instead of failing the listing. `datasource_name_text` delegates to the datasource's own `name` (`schema.table_name` for datasets, the view name for semantic views). `Slice.datasource` is intentionally unchanged: it is read by access checks and exports that depend on it being a `SqlaTable`. The relationship is registered in the soft-delete purge policy for charts (PRESERVE, like `table`); the policy validates every mapper relationship. Loading: `selectin` costs one bounded `IN (...)` query per batch of charts loaded (measured: 3 statements for a page of table-only charts, up from 2), in exchange for no per-chart query on semantic-view-heavy list pages. `datasource_id` is only unique within a `datasource_type`, so the join is guarded on the type; tests pin that a semantic-view chart never resolves to a same-id dataset and that a dangling id yields empty fields. Fixes SC-107813. Co-Authored-By: Claude Fable 5 <[email protected]>
707d303 to
c677d33
Compare
Code Review Agent Run #a92ac8Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
aminghadersohi
left a comment
There was a problem hiding this comment.
Reviewed at c677d330240a49436e31f3be19cc2da6d7a34e15. Small, well-scoped, and unusually well-tested — 52 production lines with tests that actually bind to them. I ran the suites rather than reading them. No blocking objections; one cross-PR coordination item is worth settling before merge.
Verified by running (venv on SQLAlchemy 2.0.52)
tests/unit_tests/models/slice_test.py— 15 passed. Reverting onlysuperset/models/slice.pyto base makes all 7 new tests fail, so they genuinely pin the new behaviour rather than passing vacuously.tests/unit_tests/charts/test_chart_list_datasource.py— 3 passed.- No N+1. I loaded 5 charts (3 semantic-view, 2 dataset) and counted SQL: 3 SELECTs total, constant in row count — the base query, the
subqueryload fortable, and one boundedselectinforsemantic_view. Thelazy="selectin"reasoning atsuperset/models/slice.py:179is accurate. Mapper configuration emits zero SQLAlchemy warnings;viewonly=Truekeepssemantic_viewfrom contending withtableoverdatasource_id. - The −21 is fully subsumed. The hand-rolled
f"{schema}.{table_name}"in the olddatasource_name_textis exactlySqlaTable.name(superset/connectors/sqla/models.py:1697), sogetattr(..., "name", None)is faithful. The droppedif self.table:short-circuit and the Query-object comment indatasource_urlare subsumed by thegetattrdefault, which is strictly more defensive than what it replaced. - A missing or deleted view degrades, it does not raise. With a real
session.delete(...)of the view, all four helpers returnNoneand the listing survives — a chart list will not 500 on one dangling row. purge_policy.pyis a required companion, not scope creep. Reverting only that file produces 12 failures intests/unit_tests/commands/deletion_retention/test_purge_policy.py. The registry does discovered-vs-declared relationship drift detection (superset/commands/deletion_retention/purge_policy.py:392), so addingSlice.semantic_viewobliges a declaration. The appendedPRESERVElands correctly because entries 9–16 are allPRESERVE.- Not an information leak.
ChartRestApi.base_filtersscopes the list byChartFilter, and naming a chart's semantic view is symmetric with the existing unconditional naming of its dataset. No new disclosure surface.
1. Coordination: #43781 also adds datasource resolution to Slice
master today has neither semantic_view, _display_datasource, nor resolved_datasource — so #43781 (which adds Slice.resolved_datasource and uses it inside the dashboard access check) and this PR are both adding chart→datasource resolution to the same class from a clean base. Two concerns:
- Mechanical. If #43781 also declares its own
semantic_viewrelationship, a clean auto-merge can leave twosemantic_view = relationship(...)in one class body. Python silently keeps the last one — no error, no warning — and you are left with two resolvers that can drift. - Semantic, and the reason I'd raise this at all. The docstring at
superset/models/slice.py:213states thatdatasource"deliberately staysSqlaTable-only because access checks and exports depend on that type." #43781 makes an access check depend on semantic-view resolution, which invalidates that sentence. More to the point: a display resolver and an authz resolver that disagree about "what datasource is this chart on" is precisely how a permission check drifts away from what the user is shown.
Substantively the two-way dispatch in _display_datasource() looks right, and I'd expect it to agree with resolved_datasource on the common cases. The risk is maintenance, not present-tense correctness. Worth landing one shared resolver with _display_datasource() delegating to it; whoever merges second should re-check the other definition rather than trusting the merge.
2. The two test files contradict each other on datasource_link()
tests/unit_tests/models/slice_test.py:190assertsdatasource_link() == "<a>orders</a>", using aMagicMockwhoselinkis set at line 143.tests/unit_tests/charts/test_chart_list_datasource.py:104assertsdatasource_link() is None, using a realSemanticView.
The real-row test is the correct one: SemanticView has no link attribute, so getattr(..., "link", None) at superset/models/slice.py:243 returns None. I confirmed against the real class — hasattr(SemanticView, "link") is False, while name, url, and explore_url are all True.
No runtime impact: datasource_link has no callers outside slice.py (the REST list serialises datasource_name_text and datasource_url, superset/charts/api.py:217,219), and both work correctly for semantic views. But the mock asserts behaviour the production class cannot produce, and it would keep passing if someone later added a broken link. Suggest dropping view.link from the fixture and the assertion at :190, so both files agree with the comment you already wrote at test_chart_list_datasource.py:103.
Minor note on the title: "name and link" is accurate for the list itself (name and explore URL both resolve); the legacy datasource_link HTML helper is the part that stays None.
3. Nit: icons still renders href="None"
superset/models/slice.py:397 — escape(self.datasource_edit_url) yields the literal string None when the URL is None (confirmed: escape(None) → 'None'). Line 398 directly below received exactly this fix via or "". For a chart whose semantic view was deleted — the case test_semantic_view_chart_with_deleted_view_degrades_to_empty pins — icons emits href="None". Pre-existing, and it's the same one-token fix already applied on the next line.
Nice work on the collision fixture with the shared datasource_id — that's the failure mode this class of bug actually produces, and pinning the sort-order behaviour as an explicit characterisation test instead of quietly "fixing" it was the right call.
Disclosure: this review was performed by an AI agent (Claude) on behalf of @aminghadersohi. Claims marked as run were verified by executing the test suites at the reviewed commit; the #43781 overlap was assessed from master state and this PR's diff, without opening that PR.
…pported-type gate pin, list-widening docs Review follow-ups on apache#43781 plus the rebase onto master: - rebased over apache#43649's semantic-view display work; the resolver now uses the new type-guarded semantic_view relationship as its fast path instead of a DAO query - entitled-visibility list test repointed at a non-colliding view id so it discriminates the type-aware join (the colliding view keeps its own entitled-visibility test); gate-level denial pinned for an unsupported datasource_type - UPDATING.md records the all_datasource_access list widening (chart-less no-viewer dashboards now listed, matching the object gate) and the branch-C comment scopes its never-yielded claim to ordinary users Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
SUMMARY
With
SEMANTIC_LAYERSenabled, a chart can be built on a semantic view instead of a dataset. In the Charts list, the Datasource column for every such chart was blank (no name, no link), and the chart API returneddatasource_name_text: null/datasource_url: nullfor it — regular-dataset charts on the same page rendered normally.Root cause.
Slice's display helpers (datasource_url,datasource_name_text,datasource_link,datasource_edit_url,icons) resolve the datasource only through theSqlaTablerelationship (Slice.table, which is correctly guarded ondatasource_type == 'table'), so for asemantic_viewchart they sawNone.Fix.
Slice.semantic_viewrelationship mirroringSlice.table(primaryjoinondatasource_idanddatasource_type == 'semantic_view',viewonly=True,lazy="selectin").Slice._display_datasource()that dispatches ondatasource_typeand never falls back across types; route the five display helpers through it withgetattrguards, so an unresolved reference yieldsNonefor that one chart instead of failing the listing.datasource_name_textnow delegates to the datasource's ownname(schema.table_namefor datasets, the view name for semantic views) — identical output for datasets.PRESERVE, liketable); the policy validates every mapper relationship onSlice.Design notes.
Slice.datasourceis intentionally unchanged: it is read by access checks, dashboard dataset collection and exports that depend on it being aSqlaTable. Reconciling that is a separate follow-up.datasource_idis only unique within adatasource_type— a semantic view and a dataset routinely share an id. The guarded join means a semantic-view chart can never be labelled with a same-id dataset (tested with a deliberate collision on real rows).selectinadds one boundedIN (...)query per batch of charts loaded (measured: 3 statements for a page of table-only charts, up from 2), in exchange for no per-chart query on semantic-view-heavy list pages.SemanticViewimport inslice.pyisTYPE_CHECKING-only: a module-top import is a real cycle (connectors/sqla/models→models/slice→semantic_layers/models→semantic_layers/mapper→connectors/sqla/models). The relationship names its target as a string.No migration, no new API fields, no frontend change (the list already renders
datasource_name_text/datasource_url).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Charts list, chart on a Snowflake semantic view (
TPCDS_SEMANTIC_VIEW_SM):Before — empty Datasource cell:
After — view name linked to Explore:
API, same chart:
TESTING INSTRUCTIONS
Automated:
test_chart_list_datasource.pyuses real SQLite rows with a semantic view and a dataset sharing the same id, plus a chart on each: the semantic-view chart resolves to the view, the dataset chart to the dataset; a dangling view id degrades tonullfields without error; holds withSEMANTIC_LAYERSoff.Manual (feature flag
SEMANTIC_LAYERSon):datasource_type=semantic_view&datasource_id=<id>.GET /api/v1/chart/<id>→datasource_name_textanddatasource_urlare populated.ADDITIONAL INFORMATION
SEMANTIC_LAYERS(to reproduce; the fix itself is flag-independent)Known adjacent gaps, deliberately not in this PR: the Charts-list "Dataset" filter dropdown and text search still only cover regular datasets, and the chart access filter joins
datasource_idto datasets without a type guard — same id-collision family, tracked separately.🤖 Generated with Claude Code