Skip to content

fix(charts): type-aware datasource access parity for the chart list - #43848

Merged
aminghadersohi merged 7 commits into
apache:masterfrom
mikebridge:sc-119500-chartfilter-datasource-parity
Sep 18, 2026
Merged

aminghadersohi merged 7 commits into
apache:masterfrom
mikebridge:sc-119500-chartfilter-datasource-parity

Conversation

@mikebridge

@mikebridge mikebridge commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Chart-side transplant of the type-aware datasource access pattern from #43781 (SC-111233), closing SC-119500.

ChartFilter's dataset-access fallback — the only reachable list path — inner-joined Slice.datasource_id == SqlaTable.id with no datasource_type predicate, failing in both directions for charts on non-table datasource types:

What this PR does:

  • One shared type-guard predicate (table_backed_slice_join in superset/utils/filters.py): the single authoritative ON-clause consumed by both DashboardAccessFilter and ChartFilter, so the id-collision constraint cannot drift between the filters.
  • ChartFilter branch C reshape: outer, type-guarded joins; access matches through the perm columns denormalized onto Slice by set_related_perm, uniformly across perm-carrying datasource types (no per-type allowlist; NULL-perm rows can never match). Includes the semantic-layer grant clause, mirroring the dashboard filter.
  • _apply_legacy deleted: zero callers (ChartFilter.apply routes every request through _apply_viewers regardless of ENABLE_VIEWERS); deleting rather than fixing keeps exactly one definition of the access path.
  • Type-aware drill membership (Dashboard.has_member_datasource): compares (datasource_type, datasource_id) pairs — zero queries, collision-immune by construction. Both drill consumers (can_drill_dataset_via_dashboard_access, has_drill_access) use it instead of the table-shaped Dashboard.datasources set (whose export/thumbnail consumers are untouched). No user-visible drill change today (semantic views ship with drill disabled); this makes the membership primitive correct before any provider enables it.
  • Embedded-guest allowlist pinned: a guest token carrying a datasets allowlist still denies a semantic-view member chart — now asserted by tests as the decided fail-closed semantic (the allowlist is dataset-id space; resolving other types into it would reintroduce id ambiguity), with a companion control showing the same token admits the table chart whose id it names.
  • get_dataset_access_filters signature: *args: Any becomes named *extra_access_clauses with an explicit include_all keyword (deferred-in from the fix(dashboard): resolve chart datasources across types in access checks #43781 review round).

Stacked on #43781 — #43781 has merged; this branch is now rebased directly onto master and contains only its own three commits.

Review round (clean-code + tidy-first + python lenses, report in the campaign's spec repo): all three verdicts ship, 0 blocker / 0 high. The converged finding — the semantic-view/layer join block deserved the same single-definition extraction as the table join — plus eight polish items landed in the review-polish commit (semantic_view_slice_join / semantic_view_layer_join / semantic_layer_grant_clause helpers, include_all early return, membership-helper readability + id semantics, param rename, test-precision fixes).

Two planned tidyings were deliberately skipped and stay as commented accepted costs: deduping the double datasource_access perm fetch (would change get_dataset_access_filters' contract for its four other callers — belongs to a dedicated rework if it ever pays for itself) and extracting _no_viewer_fallback_query (no natural seam materialized in the reshape).

Reverted-fix control (with superset/ stashed, the new contract tests flip — both defect directions demonstrated):

FAILED …::test_list_shows_semantic_chart_to_entitled_user
FAILED …::test_list_database_grant_does_not_leak_colliding_semantic_chart
FAILED …::test_list_layer_grant_lists_all_layer_charts
FAILED …::test_list_query_chart_participates_uniformly
4 failed, 5 passed

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — list-visibility change; the contract matrix in
tests/unit_tests/charts/semantic_view_chart_filter_test.py is the behavioural spec.

TESTING INSTRUCTIONS

python -m pytest tests/unit_tests/charts tests/unit_tests/dashboards \
  tests/unit_tests/subjects tests/unit_tests/security tests/unit_tests/utils/filters_test.py -q

Manual: as a scoped user with no DAR grants the chart list shows no semantic-view charts; grant datasource_access on a semantic view (or its parent layer) → its charts appear in /chart/list/; a user granted only database access to a database containing a table that shares a semantic view's numeric id does not see that view's charts; all_datasource_access sees everything.

ADDITIONAL INFORMATION

🤖 Generated with Claude Code

https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW

@netlify

netlify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit e0c5d6a
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aac612a41580b0008148305
😎 Deploy Preview https://deploy-preview-43848--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.

@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.42%. Comparing base (77dbaaf) to head (e0c5d6a).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #43848   +/-   ##
=======================================
  Coverage   80.41%   80.42%           
=======================================
  Files        2932     2932           
  Lines      174621   174663   +42     
  Branches    40559    40565    +6     
=======================================
+ Hits       140422   140467   +45     
+ Misses      31532    31530    -2     
+ Partials     2667     2666    -1     
Flag Coverage Δ
hive 37.33% <34.28%> (-0.01%) ⬇️
mysql 56.60% <94.28%> (+<0.01%) ⬆️
postgres 56.61% <94.28%> (+<0.01%) ⬆️
presto 39.22% <34.28%> (-0.01%) ⬇️
python 84.79% <100.00%> (+0.01%) ⬆️
sqlite 56.31% <94.28%> (+<0.01%) ⬆️
unit 76.47% <100.00%> (+0.05%) ⬆️

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.

@mikebridge
mikebridge force-pushed the sc-119500-chartfilter-datasource-parity branch from 868f550 to ec9d554 Compare September 4, 2026 05:23
@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Sep 5, 2026
mikebridge and others added 3 commits September 8, 2026 09:48
The chart list's dataset-access fallback inner-joined
Slice.datasource_id == SqlaTable.id with no datasource_type predicate,
failing in both directions for charts on non-table datasource types:
semantic-view charts were dropped from the list for users holding the
view's (or its parent layer's) datasource_access grant, and the type-less
join could bind a semantic-view chart to an unrelated table sharing its
numeric id, leaking it to holders of the colliding table's database
grant (SC-119500; the dashboard-side siblings were fixed in apache#43781).

- table_backed_slice_join in utils/filters.py is the single authoritative
  type-guarded ON-clause (FR-004); DashboardAccessFilter and ChartFilter
  both consume it
- ChartFilter branch C: outer type-guarded joins + the semantic-layer
  grant clause, mirroring DashboardAccessFilter (FR-002); access matches
  through the perm columns denormalized by set_related_perm, uniformly
  across perm-carrying types
- the dead _apply_legacy path (zero callers) is deleted, not fixed
- get_dataset_access_filters grows named extra_access_clauses and an
  explicit include_all (deferred-in from the apache#43781 review round)
- new contract-matrix regression file pins every grant x type cell,
  including the id-collision control

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Dashboard.has_member_datasource compares (datasource_type,
datasource_id) pairs — zero queries, immune to numeric-id collisions —
and both drill consumers use it instead of the table-shaped
Dashboard.datasources set, whose members never include semantic views
(FR-005; membership was vacuously false, and the id-set variant could
match a colliding non-member table). Dashboard.datasources itself is
unchanged for its export/thumbnail consumers.

The embedded-guest datasets allowlist behaviour for non-table member
charts is pinned by tests as the decided fail-closed semantic (FR-006):
the allowlist is dataset-id space, so a semantic-view member chart is
denied even when the token allowlists its colliding numeric id.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Three-lens round (clean-code, tidy-first, python) over the parity change:

- extract the semantic-view sibling helpers (semantic_view_slice_join,
  semantic_view_layer_join, semantic_layer_grant_clause) so the other
  type-guarded join and the layer grant clause also have exactly one
  definition across both list filters (the round's converged MEDIUM)
- get_dataset_access_filters: include_all now returns an explicit
  always-true clause early, skipping the grant lookups; clauses list
  keeps the ColumnElement[bool] typing end-to-end
- has_member_datasource: named locals, documented duck-typing posture
  and the int-id comparison semantics (string-id explorables fail closed)
- can_drill_dataset_via_dashboard_access: parameter renamed to
  datasource to match its widened type
- chart filter documents the deliberate include_all asymmetry with the
  dashboard filter; test docstrings corrected (all_datasource_access is
  the apply() early return, not the fallback); extra-clause unit pin now
  asserts OR-composition

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
@mikebridge
mikebridge force-pushed the sc-119500-chartfilter-datasource-parity branch from ec9d554 to c5eea02 Compare September 8, 2026 15:50
@mikebridge
mikebridge marked this pull request as ready for review September 8, 2026 15:50
Comment thread superset/charts/filters.py Resolved
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged security issue is correct. The code changes implement type-aware outer joins to ensure that charts on non-table datasources (like semantic views) are correctly included in visibility filters. Because these joins are outer joins, they can include rows where the datasource has been deleted, potentially leaving stale Slice.perm values. However, as noted in the code comments, the object-level access gate remains authoritative and will correctly reject access to these charts, making this an accepted edge case shared with the dashboard filter logic.

No further code changes are required to resolve this specific issue, as the existing object-level gate provides the necessary security enforcement.

superset/charts/filters.py

# A chart whose
            # datasource row is hard-deleted can still match its stale
            # denormalized perm here; the object gate stays authoritative
            # and denies (accepted edge, shared with the dashboard filter).

@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Sep 8, 2026
@aminghadersohi
aminghadersohi self-requested a review September 8, 2026 16:41
@bito-code-review

bito-code-review Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #97d5f9

Actionable Suggestions - 0
Additional Suggestions - 3
  • tests/unit_tests/utils/filters_test.py - 2
    • Redundant inline import · Line 72-72
      `security_manager` is already imported at module level (line 24), so this inline re-import is redundant. Only `SqlaTable` needs the inline import (circular dependency). Removing it keeps imports at module level per repo convention.
    • Unverified skip behavior · Line 100-100
      The docstring claims `include_all` skips the grant lookups, but the test only asserts the return value is `"true"`. If the implementation regressed to still call `get_accessible_databases`/`user_view_menu_names`, this test would still pass. Assert the mocks were not called to lock in the documented behavior.
  • superset/utils/filters.py - 1
    • Wasted grant query · Line 42-43
      `include_all=True` returns `true()` and discards `extra_access_clauses`, but the dashboard caller computes `layer_grant_clause = semantic_layer_grant_clause()` unconditionally before the call, so `user_view_menu_names("datasource_access")` still runs for `all_datasource_access` holders — defeating the documented 'skips the grant lookups' optimization. Compute the clause only when `include_all` is False.
Review Details
  • Files reviewed - 8 · Commit Range: 0b205b1..c5eea02
    • superset/charts/filters.py
    • superset/dashboards/filters.py
    • superset/models/dashboard.py
    • superset/security/manager.py
    • superset/utils/filters.py
    • tests/unit_tests/charts/semantic_view_chart_filter_test.py
    • tests/unit_tests/dashboards/semantic_view_access_test.py
    • tests/unit_tests/utils/filters_test.py
  • Files skipped - 1
    • UPDATING.md - Reason: Filter setting
  • 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

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Sep 9, 2026

@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.

Net security improvement, verified by reverting only the production files: 11 tests flip, including the collision-rejection cases. Blocking for merge, not review: the branch conflicts with master and needs a rebase.

Comment thread superset/charts/filters.py Outdated
# denormalized onto Slice by ``set_related_perm``. A chart whose
# datasource row is hard-deleted can still match its stale
# denormalized perm here; the object gate stays authoritative
# and denies (accepted edge, shared with the dashboard filter).

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.

Slice.perm can't match after an ORM delete: dataset_after_delete drops the datasource_access PVM and hard_delete fires it per row. The reachable residual is schema_perm/catalog_perm, which survive deletion — worth narrowing this comment and pinning it with a test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed — narrowed in 8a5bd06f91. The comment now names schema_perm / catalog_perm explicitly and qualifies this as the table ORM-delete case, rather than implying a stale Slice.perm can match after the PVM is dropped.

Added a lifecycle test covering it end to end: the dataset grant disappears on delete, the schema/catalog list match remains, and the datasource-based object gate denies. That pins the narrower residual you identified instead of the mechanism originally described.

Comment thread superset/models/dashboard.py Outdated
# explorable with a string id never matches the integer
# ``datasource_id`` column, which is likewise fail closed.
candidate_type = getattr(datasource, "type", None)
candidate_id = datasource.id

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.

Docstring says an object with no id is "simply no member — fail closed", but direct attribute access raises AttributeError instead. type above already uses getattr; make id symmetric.

Suggested change
candidate_id = datasource.id
candidate_id = getattr(datasource, "id", None)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch — the docstring promised "no id is simply no member, fail closed" while direct attribute access raised AttributeError instead.

Took your suggestion in 8a5bd06f91 with an explicit local annotation, and added a missing-id regression that raised AttributeError before the change and returns False now.

@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Sep 15, 2026

@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.

Re-reviewed at 0cde1cf: the round-1 merge blocker is cleared — the branch is even with master and mergeable, and neither merge commit changed any PR-owned code. The two open threads on charts/filters.py and models/dashboard.py are unchanged.

Answer PRRT_kwDOAlosUs6gwOhy by naming the schema/catalog grants that
survive table ORM deletion and pinning their list/object access behavior
with real permission lifecycle tests. Dataset datasource_access grants
are removed, so the comment must not imply they survive deletion.

Answer PRRT_kwDOAlosUs6gwOh0 by safely reading a duck-typed datasource id
so dashboard membership returns False instead of raising AttributeError.
Add a regression test verified by reverting and restoring the guard.

@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.

Verified at 8a5bd06 by execution, not by reading the replies: the missing-id guard returns False (reverting it reds only the new regression), and the deletion residual is pinned — schema/catalog grants list the orphan, the object gate denies it against a known-allow control.

@bito-code-review

bito-code-review Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b435d1

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: c5eea02..8a5bd06
    • superset/charts/filters.py
    • superset/models/dashboard.py
    • tests/unit_tests/charts/semantic_view_chart_filter_test.py
    • tests/unit_tests/dashboards/semantic_view_access_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

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Sep 17, 2026
Resolve the sole conflict by retaining both cast and TYPE_CHECKING imports. Add explicit annotations to new branch variables to satisfy the required Python review; no behavior changes.
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants