Skip to content

fix(charts): support saved_query datasource in chart create/update - #43499

Open
rusackas wants to merge 5 commits into
masterfrom
fix/issue-29697-saved-query-datasource-name
Open

rusackas wants to merge 5 commits into
masterfrom
fix/issue-29697-saved-query-datasource-name

Conversation

@rusackas

@rusackas rusackas commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Creating (or updating) a chart with datasource_type: saved_query raised a fatal 'SavedQuery' object has no attribute 'name' error. CreateChartCommand/UpdateChartCommand.validate() read datasource.name to populate datasource_name, and every other datasource type (SqlaTable, Query, SemanticView) exposes a name, but SavedQuery only had a label column. This adds a name property to SavedQuery that returns label, so it behaves like the rest of the Datasource union instead of special-casing the command layer.

saved_query is now a fully persistable chart datasource type: the ck_chart_datasource CHECK constraint on slices.datasource_type is extended (migration dfa683969f48) to allow it alongside table/semantic_view, matching what validate_chart_datasource_type already accepted.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (backend-only fix, no UI change)

TESTING INSTRUCTIONS

  • Added a regression test that pins the bug: tests/unit_tests/commands/chart/test_access_checks.py::test_create_chart_command_supports_saved_query_datasource builds a real SavedQuery (not a mock) and asserts CreateChartCommand.validate() no longer raises AttributeError and correctly derives datasource_name from label.
  • tests/integration_tests/charts/api_tests.py::TestChartApi::test_create_chart_from_saved_query posts a real chart-create request end to end and asserts a 201.
  • Manually: POST /api/v1/chart/ with datasource_type: "saved_query" and a valid datasource_id should now create the chart instead of returning a 500.
  • pytest tests/unit_tests/commands/chart/test_access_checks.py tests/unit_tests/models/sql_lab_test.py

ADDITIONAL INFORMATION

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b8bc04

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: a0fe61f..a0fe61f
    • superset/models/sql_lab.py
    • tests/unit_tests/commands/chart/test_access_checks.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added the api:charts Related to the REST endpoints of charts label Aug 25, 2026
@rusackas
rusackas requested review from betodealmeida and sha174n and a lite review from Copilot and removed request for betodealmeida August 25, 2026 04:36
Comment thread superset/models/sql_lab.py Resolved
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The label property in SavedQuery is nullable, but the new name property is annotated to return a str, which can lead to runtime errors or None values being stored where a string is expected. To resolve this, you should provide a non-null fallback (e.g., an empty string) and update the return type annotation to reflect that it may be optional if label is missing.

Here is the corrected implementation for superset/models/sql_lab.py:

    @property
    def name(self) -> str:
        """
        Expose ``label`` as ``name`` so callers that treat a ``SavedQuery`` as
        a generic datasource (e.g. chart create/update commands) can rely on
        a uniform ``name`` attribute across all datasource types.
        """
        return self.label or ""

There are no other comments on this PR to address. Would you like me to check for any other potential issues in the codebase?

superset/models/sql_lab.py

@property
    def name(self) -> str:
        """
        Expose ``label`` as ``name`` so callers that treat a ``SavedQuery`` as
        a generic datasource (e.g. chart create/update commands) can rely on
        a uniform ``name`` attribute across all datasource types.
        """
        return self.label or ""

Copilot AI 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.

Pull request overview

Fixes saved-query datasource support for chart creation and updates by exposing SavedQuery.label as name.

Changes:

  • Adds SavedQuery.name.
  • Adds chart validation regression coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Review summary
tests/unit_tests/commands/chart/test_access_checks.py Adds validation coverage, but not full access or persistence coverage.
superset/models/sql_lab.py Adds name, but saved-query access checks and slice persistence still require missing permission/data attributes.
Suppressed comments (1)

tests/unit_tests/commands/chart/test_access_checks.py:122

  • This regression test patches out security_manager.raise_for_access, so it only proves that name exists and cannot detect the subsequent access/persistence failures described above. It also does not exercise the advertised UpdateChartCommand path. Add coverage for both command paths that validates the selected saved-query access contract and the chart persistence hook.
    with patch(
        "superset.commands.chart.create.get_datasource_by_id",
        return_value=saved_query,
    ):
        with patch("superset.commands.chart.create.security_manager.raise_for_access"):
            with patch(
                "superset.commands.chart.create.populate_subjects",
                return_value=[],
            ):

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.76%. Comparing base (5e6e19e) to head (0053e08).

Files with missing lines Patch % Lines
superset/models/sql_lab.py 84.61% 5 Missing and 1 partial ⚠️
superset/models/slice.py 60.00% 1 Missing and 1 partial ⚠️
superset/security/manager.py 95.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #43499       +/-   ##
===========================================
+ Coverage   56.59%   84.76%   +28.16%     
===========================================
  Files        3071     3071               
  Lines      206037   206141      +104     
  Branches    48506    48523       +17     
===========================================
+ Hits       116607   174730    +58123     
+ Misses      88317    28108    -60209     
- Partials     1113     3303     +2190     
Flag Coverage Δ
hive 34.48% <27.27%> (-0.01%) ⬇️
mysql 52.61% <65.45%> (?)
postgres 52.63% <65.45%> (?)
presto 36.21% <27.27%> (-0.01%) ⬇️
python 87.76% <89.09%> (+51.50%) ⬆️
sqlite 52.38% <64.54%> (?)
unit 82.53% <85.45%> (?)

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.

@pull-request-size pull-request-size Bot added size/L and removed size/M labels Aug 25, 2026
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #100eb3

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/models/sql_lab.py - 1
    • CWE-20: Schema perm inconsistent API · Line 577-577
      The `schema_perm` property uses direct string formatting `f"{self.database.database_name}.{self.schema}"` instead of calling `security_manager.get_schema_perm()`, which deviates from the pattern used by `SqlaTable.get_schema_perm()` (line 1677 of sqla/models.py) and `Query.schema_perm`. This also skips the edge-case handling in `get_schema_perm()` that returns `None` for empty schemas instead of producing malformed strings like `[db].`.
Review Details
  • Files reviewed - 2 · Commit Range: a0fe61f..2e8931a
    • superset/models/sql_lab.py
    • tests/unit_tests/commands/chart/test_access_checks.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/models/sql_lab.py Resolved
@netlify

netlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #d62867

Actionable Suggestions - 0
Additional Suggestions - 2
  • superset/daos/datasource.py - 1
    • Misleading not-found error · Line 92-102
      Raising `DatasourceNotFound` (404 'Datasource does not exist') for a SavedQuery that exists but lacks a database is misleading — the datasource isn't missing, it's invalid. The comment asks for a 'controlled validation error'; `DatasourceValueIsIncorrect` (422, already imported) fits better and avoids a false 404 via `get_datasource_by_id` → `DatasourceNotFoundValidationError`.
  • tests/unit_tests/commands/chart/test_access_checks.py - 1
    • Misleading test coverage · Line 143-166
      The test name says it rejects a saved query without a database, but it patches `get_datasource_by_id` to raise `DatasourceNotFoundValidationError` directly — no SavedQuery with `db_id=None` is created and the new DAO guard is never exercised. It only verifies `validate()` propagates the error to `ChartInvalidError`. Patch the DAO path or rename the test.
Review Details
  • Files reviewed - 3 · Commit Range: 2e8931a..b20876c
    • superset/daos/datasource.py
    • tests/unit_tests/commands/chart/test_access_checks.py
    • tests/unit_tests/datasource/dao_tests.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from b20876c to decf0eb Compare September 23, 2026 14:09
@rusackas

Copy link
Copy Markdown
Member Author

Looks like #43500 solved the underlying #29697 crash the other way, rejecting saved_query/query as chart datasources instead of making them work, and #44416 locked that in with an explicit TABLE/SEMANTIC_VIEW allowlist. That's why validate_chart_datasource_type now rejects saved_query on master, and this PR's own regression test fails after a rebase. Still worth landing, or close this in favor of #43500?

@bito-code-review bito-code-review Bot 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.

Code Review Agent Run #77baf9

Actionable Suggestions - 1
  • superset/models/sql_lab.py - 1
Additional Suggestions - 1
  • superset/models/sql_lab.py - 1
    • unguarded database deref · Line 613-613
      `perm`/`schema_perm`/`catalog_perm` dereference `self.database.database_name` unguarded, while the sibling `data` property guards `if self.database:`. The DAO guard (datasource.py:92) checks `db_id is None`, not the relationship being loaded, so a saved query with an orphaned `db_id` (FK set, `database` None) passes the guard and crashes here. Consider guarding like `data`.
Review Details
  • Files reviewed - 4 · Commit Range: f6e8aef..decf0eb
    • superset/daos/datasource.py
    • superset/models/sql_lab.py
    • tests/unit_tests/commands/chart/test_access_checks.py
    • tests/unit_tests/datasource/dao_tests.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/models/sql_lab.py Resolved
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #03285a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: decf0eb..7188d5f
    • superset/models/sql_lab.py
    • tests/unit_tests/commands/chart/test_access_checks.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review bito-code-review Bot 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.

Code Review Agent Run #b02e31

Actionable Suggestions - 1
  • superset/commands/chart/utils.py - 1
Review Details
  • Files reviewed - 1 · Commit Range: 7188d5f..3ea862d
    • superset/commands/chart/utils.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/commands/chart/utils.py Resolved
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #7973e4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 3ea862d..761be17
    • tests/unit_tests/commands/chart/create_test.py
    • tests/unit_tests/commands/chart/update_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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added the risk:db-migration PRs that require a DB migration label Sep 29, 2026

@bito-code-review bito-code-review Bot 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.

Code Review Agent Run #4e1e9f

Actionable Suggestions - 1
  • tests/integration_tests/charts/semantic_save_tests.py - 1
Review Details
  • Files reviewed - 3 · Commit Range: 761be17..760c2a6
    • superset/migrations/versions/2026-09-29_00-00_dfa683969f48_allow_saved_query_chart_datasource.py
    • tests/integration_tests/charts/api_tests.py
    • tests/integration_tests/charts/semantic_save_tests.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #50bb06

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 760c2a6..24e192d
    • tests/integration_tests/charts/semantic_save_tests.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 evan@preset.io.

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 30, 2026
@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from 24e192d to 9443417 Compare September 30, 2026 23:54
Comment thread superset/commands/chart/utils.py Resolved
Comment thread tests/unit_tests/models/sql_lab_test.py Resolved
Comment thread superset/models/sql_lab.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@rusackas the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from 25b57dd to d7b0dfe Compare October 21, 2026 01:59
Comment thread superset/security/manager.py Resolved
Comment thread tests/unit_tests/models/sql_lab_test.py Resolved
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@rusackas the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

rusackas added a commit that referenced this pull request Oct 21, 2026
…rent migration, cover catalog_perm

Address review on #43499:

- `database_after_update` only walked `SqlaTable` rows, so charts backed by
  a saved query kept `[old].[...]` perm/schema_perm/catalog_perm after the
  database was renamed and would match a grant on an unrelated connection
  that later took the old name. Rewrite those chart rows on rename too,
  sharing the perm-string helper with `saved_query_before_update`.
- Re-parent the `allow_saved_query_chart_datasource` migration onto the
  current head (`d623a0cb6bb0`) and make the docstring agree with
  `down_revision`.
- Test the catalog half of the sync for real: move a saved query between
  catalogs and delete one with a non-null catalog, asserting the replaced
  and cleared `catalog_perm`; add a database-rename regression test.

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from d7b0dfe to c14bd6d Compare October 21, 2026 04:26
Comment thread superset/commands/chart/utils.py Resolved
Comment thread superset/security/manager.py Resolved
Comment thread superset/commands/chart/create.py Resolved
Comment thread superset/security/manager.py Resolved
Comment thread superset/security/manager.py Resolved

with (
patch(
"superset.commands.chart.utils.security_manager.can_access_all_queries",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test forces can_access_all_queries to True and mocks raise_for_access, and the API test runs as Admin, so the ownership rejection is only exercised by calling the helper directly with mocked ownership. If CreateChartCommand stopped calling raise_for_saved_query_ownership, every test here would still pass. Could an API test cover a non-admin caller with chart-create and schema access but no all_query_access, expecting 403 and no persisted Slice for another user's saved query, and 201 for their own?

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Oct 21, 2026
@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from 21d7c9f to 3a4b717 Compare October 22, 2026 04:44
Comment thread superset/models/sql_lab.py Resolved
Comment thread superset/security/manager.py Resolved
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Oct 22, 2026
Comment thread superset/commands/chart/utils.py Outdated
database, so editorship of one (being its creator) must not stand in for a
database, catalog, or schema grant: require the real grant.
"""
security_manager.raise_for_access(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With editorship now off for saved queries, an owner whose only grant is catalog_access on the database's default catalog gets a 403 binding a chart to their own saved query that has catalog unset. can_access_schema checks the raw datasource.catalog, which is None here, so the catalog grant is skipped, even though catalog_perm and schema_perm on the same saved query now resolve against the default catalog. Should the access check resolve the effective catalog the same way, so the grant that the chart's own perm strings match is honored?


# The bulk update above bypasses ``saved_query_before_update``, so
# re-copy the saved queries' perm strings onto their dependent charts.
if database := db.session.query(Database).get(database_id):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nothing exercises this resync: test_update_with_catalog_change mocks _update_catalog_attribute entirely, and the model tests drive the ORM listeners, so deleting this call leaves the suite green. Could a test persist a saved-query chart, run the real _update_catalog_attribute from catalog A to B, and assert after expiring the session that the chart's catalog_perm and schema_perm both carry B?

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@rusackas the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Possible DB migration conflict

@rusackas the base branch master picked up a new database migration under superset/migrations/ after this PR was opened, and this PR adds or modifies migration files too. Alembic migrations form a single linear chain, so if both branch off the same parent revision, merging this PR as-is could leave the migration history with two heads instead of one, which makes superset db upgrade fail with Multiple head revisions are present.

To check and, if needed, fix this:

  1. Rebase this branch onto the latest master.
  2. Run superset db heads. If it lists more than one revision, you have a conflict.
  3. In your new migration's script, update down_revision (and the Revises comment) to point at the other head instead, so the chain has a single head again.

See Merging DB Migrations in the contributing guide for a worked example.

@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from cb86146 to 478b840 Compare October 28, 2026 22:11
@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Oct 31, 2026
rusackas and others added 5 commits October 30, 2026 20:34
Rebased squash of the saved_query chart datasource work onto current master.

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Require a real database/schema grant (not saved-query editorship) when binding a
chart to a saved query, fall back to the default catalog for catalog_perm,
resync dependent charts on catalog changes, and limit database-rename resync to
saved queries that have charts, resolving the default catalog once.

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…asources

Only pass allow_editorship=False when binding a chart to a saved query;
tables and semantic views go through the same raise_for_access(datasource=...)
call as before. The extra kwarg broke semantic_save_tests' call assertion,
and because that test aborted before cleanup, its leftover semantic_view
chart cascaded into the reports, dashboards export, and change_records
failures later in the integration run.

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…head

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@rusackas
rusackas force-pushed the fix/issue-29697-saved-query-datasource-name branch from 478b840 to 0053e08 Compare October 31, 2026 03:44
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Oct 31, 2026

This branch has not been deployed

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

Labels

api:charts Related to the REST endpoints of charts preset-io risk:db-migration PRs that require a DB migration size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fatal error when creating a chart from a saved_query via API call

3 participants