Skip to content

fix(datasource): map combined_list to can_read so Gamma can list datasets#39947

Open
msyavuz wants to merge 2 commits into
masterfrom
msyavuz/fix/datasource-combined-list-permission
Open

fix(datasource): map combined_list to can_read so Gamma can list datasets#39947
msyavuz wants to merge 2 commits into
masterfrom
msyavuz/fix/datasource-combined-list-permission

Conversation

@msyavuz
Copy link
Copy Markdown
Member

@msyavuz msyavuz commented May 7, 2026

SUMMARY

DatasourceRestApi.combined_list (added in #37815) relied on the auto-derived can_combined_list on Datasource permission. Because can_combined_list is not in SupersetSecurityManager.READ_ONLY_PERMISSION, _is_alpha_only flags it as Alpha-only and excludes it from the Gamma role, so Gamma users get a 403 on the dataset list page (/api/v1/datasource/?q=...).

Map the method to read via method_permission_name so the FAB check uses can_read on Datasource, which is already a READ_ONLY_PERMISSION and gets granted to Admin/Alpha/Gamma via the standard role sync.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend permission mapping change, no UI difference.

TESTING INSTRUCTIONS

  1. Apply the patch and run superset init to register can_read on Datasource and re-sync role grants.
  2. Log in as a Gamma user and navigate to the datasets list — request to /api/v1/datasource/?q=... should return 200 instead of 403.
  3. Verify Admin/Alpha still load the page as before.
  4. Run pytest tests/integration_tests/datasource/api_tests.py::TestDatasourceApi::test_combined_list_invalid_order_column tests/integration_tests/datasource/api_tests.py::TestDatasourceApi::test_combined_list_semantic_layers_off.

ADDITIONAL INFORMATION

  • Has associated issue: No
  • Required feature flags: None
  • Changes UI: No — backend-only
  • Includes DB Migration: No
  • Introduces new feature or API: No
  • Removes existing feature or API: No

Note: deployments must run superset init after upgrading so the new can_read on Datasource permission is registered and granted to existing roles.

…sets

The combined_list endpoint added in #37815 used the auto-derived
`can_combined_list on Datasource` permission, which is not in
READ_ONLY_PERMISSION and is therefore excluded from the Gamma role by
_is_alpha_only. Map it to `can_read on Datasource` instead so Gamma
inherits access alongside Alpha and Admin.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 7, 2026

Code Review Agent Run #5bd230

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/integration_tests/datasource/api_tests.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: bdcad9b..bdcad9b
    • superset/datasource/api.py
    • tests/integration_tests/datasource/api_tests.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added the api Related to the REST API label May 7, 2026
@dosubot dosubot Bot added the authentication:RBAC Related to RBAC label May 7, 2026
@msyavuz msyavuz requested a review from betodealmeida May 7, 2026 11:09
Comment on lines +215 to +216
security_manager.add_permission_view_menu("can_read", "Datasource")
perm = security_manager.find_permission_view_menu("can_read", "Datasource")
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.

Suggestion: This test was migrated to grant can_read on Datasource, but other combined_list tests in the same file still grant can_combined_list. Because the endpoint permission is now can_read, those tests can fail with 403 when run in isolation (or become order-dependent if this test runs first and mutates role permissions). Update the remaining combined_list tests to grant can_read (or move permission setup to a shared fixture) so each test is self-contained. [logic error]

Severity Level: Major ⚠️
-`test_combined_list_semantic_layers_off` fails when run in isolation.
- ⚠️ Test suite becomes order-dependent for combined_list tests.
- ⚠️ Flaky CI possible if test ordering or selection changes.
Steps of Reproduction ✅
1. Note the new permission mapping for the endpoint in `superset/datasource/api.py`:
`DatasourceRestApi` defines `method_permission_name = {"combined_list": "read"}` at lines
40–48 and the `combined_list` view at lines 11–20 and 42–48 (second snippet, lines 11–20
and 42–48) is decorated with `@protect()`, which enforces `can_read` on class permission
`Datasource`.

2. In `tests/integration_tests/datasource/api_tests.py`, inspect
`test_combined_list_invalid_order_column` at lines 208–223: it creates and grants
`("can_read", "Datasource")` to the Admin role via
`security_manager.add_permission_view_menu("can_read", "Datasource")` and
`security_manager.add_permission_role(admin_role, perm)` (lines 215–218), so this test
aligns with the new mapping.

3. In the same file, inspect `test_combined_list_semantic_layers_off` at lines 231–255: it
still creates and grants `("can_combined_list", "Datasource")` (lines 238–243) and never
creates or assigns `("can_read", "Datasource")`. When this test is run in isolation, the
Admin role lacks `can_read` on `Datasource`, so the `@protect()` check for `combined_list`
fails with 403 before the body executes, even though `security_manager.can_access` is
patched to return True (lines 231–244).

4. Run this test alone, e.g. `pytest
tests/integration_tests/datasource/api_tests.py::TestDatasourceApi::test_combined_list_semantic_layers_off`.
The request to `GET
/api/v1/datasource/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)`
at lines 248–251 returns HTTP 403 instead of the expected 200 at line 253, causing the
test to fail; if `test_combined_list_invalid_order_column` runs first in the same process
it seeds `can_read` and masks the bug, making the behavior order-dependent.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/integration_tests/datasource/api_tests.py
**Line:** 215:216
**Comment:**
	*Logic Error: This test was migrated to grant `can_read` on `Datasource`, but other `combined_list` tests in the same file still grant `can_combined_list`. Because the endpoint permission is now `can_read`, those tests can fail with 403 when run in isolation (or become order-dependent if this test runs first and mutates role permissions). Update the remaining `combined_list` tests to grant `can_read` (or move permission setup to a shared fixture) so each test is self-contained.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.89%. Comparing base (b5186d1) to head (72649ca).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #39947   +/-   ##
=======================================
  Coverage   63.88%   63.89%           
=======================================
  Files        2583     2583           
  Lines      136604   136605    +1     
  Branches    31502    31502           
=======================================
+ Hits        87276    87277    +1     
  Misses      47812    47812           
  Partials     1516     1516           
Flag Coverage Δ
hive 39.38% <100.00%> (+<0.01%) ⬆️
mysql 59.06% <100.00%> (+<0.01%) ⬆️
postgres 59.14% <100.00%> (+<0.01%) ⬆️
presto 41.08% <100.00%> (+<0.01%) ⬆️
python 60.58% <100.00%> (+<0.01%) ⬆️
sqlite 58.77% <100.00%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

…s_off

The other combined_list test was migrated to grant can_read on Datasource,
but this one still granted can_combined_list, causing 403 when run in
isolation now that the endpoint maps to can_read.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 8, 2026

Code Review Agent Run #abc845

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: bdcad9b..72649ca
    • tests/integration_tests/datasource/api_tests.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API authentication:RBAC Related to RBAC size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants