Skip to content

fix(charts): resolve semantic-view datasource name and link in chart list - #43649

Merged
aminghadersohi merged 1 commit into
apache:masterfrom
mikebridge:sc-107813-chart-list-datasource-url
Sep 3, 2026
Merged

aminghadersohi merged 1 commit into
apache:masterfrom
mikebridge:sc-107813-chart-list-datasource-url

Conversation

@mikebridge

Copy link
Copy Markdown
Member

SUMMARY

With SEMANTIC_LAYERS enabled, 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 returned datasource_name_text: null / datasource_url: null for 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 the SqlaTable relationship (Slice.table, which is correctly guarded on datasource_type == 'table'), so for a semantic_view chart they saw None.

Fix.

  • Add a type-guarded, view-only Slice.semantic_view relationship mirroring Slice.table (primaryjoin on datasource_id and datasource_type == 'semantic_view', viewonly=True, lazy="selectin").
  • Add a display-only Slice._display_datasource() that dispatches on datasource_type and never falls back across types; route the five display helpers through it with getattr guards, so an unresolved reference yields None for that one chart instead of failing the listing.
  • datasource_name_text now delegates to the datasource's own name (schema.table_name for datasets, the view name for semantic views) — identical output for datasets.
  • Register the new relationship in the soft-delete purge policy for charts (PRESERVE, like table); the policy validates every mapper relationship on Slice.

Design notes.

  • Slice.datasource is intentionally unchanged: it is read by access checks, dashboard dataset collection and exports that depend on it being a SqlaTable. Reconciling that is a separate follow-up.
  • datasource_id is only unique within a datasource_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).
  • Loading cost: selectin adds 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.
  • The SemanticView import in slice.py is TYPE_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:

before

After — view name linked to Explore:

after

API, same chart:

// before
{"datasource_type": "semantic_view", "datasource_name_text": null, "datasource_url": null}
// after
{"datasource_type": "semantic_view", "datasource_name_text": "TPCDS_SEMANTIC_VIEW_SM",
 "datasource_url": "/explore/?datasource_type=semantic_view&datasource_id=2"}

TESTING INSTRUCTIONS

Automated:

pytest tests/unit_tests/models/slice_test.py tests/unit_tests/charts/test_chart_list_datasource.py tests/unit_tests/commands/deletion_retention/ -W error::sqlalchemy.exc.SAWarning

test_chart_list_datasource.py uses 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 to null fields without error; holds with SEMANTIC_LAYERS off.

Manual (feature flag SEMANTIC_LAYERS on):

  1. Add a semantic layer + semantic view (any provider; the in-memory demo layer works) and save a chart on it.
  2. Charts list → the Datasource cell shows the view's name as a link; clicking it opens Explore on datasource_type=semantic_view&datasource_id=<id>.
  3. GET /api/v1/chart/<id> → datasource_name_text and datasource_url are populated.
  4. A chart on a regular dataset renders exactly as before.
  5. Optional collision check: if a dataset with the same numeric id as the view exists, the semantic-view chart still names the view.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: SEMANTIC_LAYERS (to reproduce; the fix itself is flag-independent)
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

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_id to datasets without a type guard — same id-collision family, tracked separately.

🤖 Generated with Claude Code

@dosubot dosubot Bot added change:backend Requires changing the backend listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. labels Aug 28, 2026
@bito-code-review

bito-code-review Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #0c4a2c

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 707d303..707d303
    • superset/commands/deletion_retention/purge_policy.py
    • superset/models/slice.py
    • tests/unit_tests/charts/test_chart_list_datasource.py
    • tests/unit_tests/models/slice_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit c677d33
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a95a01101a96a0008762663
😎 Deploy Preview https://deploy-preview-43649--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread superset/models/slice.py Resolved
@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.25%. Comparing base (040b33c) to head (c677d33).

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     
Flag Coverage Δ
hive 37.90% <20.00%> (+<0.01%) ⬆️
mysql 57.58% <50.00%> (+<0.01%) ⬆️
postgres 57.62% <50.00%> (+<0.01%) ⬆️
presto 39.80% <20.00%> (+<0.01%) ⬆️
python 83.75% <100.00%> (+0.01%) ⬆️
sqlite 57.31% <50.00%> (+<0.01%) ⬆️
unit 74.01% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The PR introduces a semantic_view relationship and updates display helpers (datasource_link, datasource_url, datasource_name_text, datasource_edit_url) to resolve through _display_datasource(), which correctly handles semantic views. However, the chart response schema (likely in superset/charts/schemas.py or similar) still relies on the hard-coded table.uuid or datasource_uuid field, which is not updated to resolve the semantic view's UUID.

To resolve this, you should update the chart response schema to resolve the datasource_uuid dynamically based on the datasource_type, similar to how the display helpers now use _display_datasource(). You can add a property or method to the Slice model that returns the correct UUID based on the datasource type, and update the schema to use this property.

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]>
@mikebridge
mikebridge force-pushed the sc-107813-chart-list-datasource-url branch from 707d303 to c677d33 Compare August 31, 2026 15:38
@bito-code-review

bito-code-review Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #a92ac8

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: c677d33..c677d33
    • superset/commands/deletion_retention/purge_policy.py
    • superset/models/slice.py
    • tests/unit_tests/charts/test_chart_list_datasource.py
    • tests/unit_tests/models/slice_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi
aminghadersohi self-requested a review September 2, 2026 20:35

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 only superset/models/slice.py to 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 subquery load for table, and one bounded selectin for semantic_view. The lazy="selectin" reasoning at superset/models/slice.py:179 is accurate. Mapper configuration emits zero SQLAlchemy warnings; viewonly=True keeps semantic_view from contending with table over datasource_id.
  • The −21 is fully subsumed. The hand-rolled f"{schema}.{table_name}" in the old datasource_name_text is exactly SqlaTable.name (superset/connectors/sqla/models.py:1697), so getattr(..., "name", None) is faithful. The dropped if self.table: short-circuit and the Query-object comment in datasource_url are subsumed by the getattr default, 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 return None and the listing survives — a chart list will not 500 on one dangling row.
  • purge_policy.py is a required companion, not scope creep. Reverting only that file produces 12 failures in tests/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 adding Slice.semantic_view obliges a declaration. The appended PRESERVE lands correctly because entries 9–16 are all PRESERVE.
  • Not an information leak. ChartRestApi.base_filters scopes the list by ChartFilter, 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_view relationship, a clean auto-merge can leave two semantic_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:213 states that datasource "deliberately stays SqlaTable-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:190 asserts datasource_link() == "<a>orders</a>", using a MagicMock whose link is set at line 143.
  • tests/unit_tests/charts/test_chart_list_datasource.py:104 asserts datasource_link() is None, using a real SemanticView.

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.

@aminghadersohi
aminghadersohi merged commit d921131 into apache:master Sep 3, 2026
73 checks passed
mikebridge added a commit to mikebridge/superset that referenced this pull request Sep 3, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend listview Namespace | Anything related to lists, such as Dashboards, Charts, Datasets, etc. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants