Skip to content

feat(charts): add extensible extra metadata column to slices#41200

Open
bsovran wants to merge 2 commits into
apache:masterfrom
bsovran:feat/chart-extra-metadata-column
Open

feat(charts): add extensible extra metadata column to slices#41200
bsovran wants to merge 2 commits into
apache:masterfrom
bsovran:feat/chart-extra-metadata-column

Conversation

@bsovran

@bsovran bsovran commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

Adds a nullable extra column to the slices table (and the Slice model) to store open-ended, structured chart metadata, mirroring the long-standing dataset extra pattern.

Charts currently have no extensible metadata field. description is unsuitable because it is user-facing prose rendered as markdown and shown as a tooltip in the Charts list. Datasets already solve this with an extra JSON-bearing column (SqlaTable.extra), and columns/metrics have their own extra as well. This change brings the same proven, low-risk pattern to charts.

Design decisions:

  • Column name extra, consistent with tables.extra and column/metric extra.
  • Type MediumText (superset.utils.core.MediumText), which resolves to TEXT on Postgres/SQLite and MEDIUMTEXT on MySQL. This matches the existing JSON-bearing chart fields params and query_context, avoids MySQL's 64KB TEXT limit, and stores identical bytes across backends (unlike a native JSON column, which MySQL normalizes/reorders).
  • Nullable, no server default. JSON is stored as a string and parsed at the application layer, exactly as SqlaTable.extra_dict does today.
  • Added extra to Slice.export_fields so it round-trips through import/export.

This PR intentionally scopes to the model + migration foundation. Exposing extra through the chart REST API (ChartPostSchema/ChartPutSchema/response schema) and any UI can follow in a separate PR.

Associated SIP: #41171

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - backend schema change with no UI surface in this PR.

TESTING INSTRUCTIONS

  1. Run superset db upgrade and confirm the extra column is added to slices (nullable).
  2. Run superset db downgrade and confirm the column is cleanly removed.
  3. Confirm superset db heads reports a single head.
  4. Set/read Slice.extra (e.g. via shell) and confirm round-trip through chart export/import.

The migration uses the idempotent add_columns/drop_columns helpers from superset/migrations/shared/utils.py, following the exact shape of the existing 94e7a3499973 (add folders to datasets) migration. Upgrade/downgrade of the additive column was exercised against a local metadata DB.

ADDITIONAL INFORMATION

  • Has associated issue: [SIP-216] Add extensible extra metadata field to charts (slices) #41171
  • Required feature flags:
  • 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

Runtime/downtime: adding a nullable column to slices is a metadata-only DDL change on Postgres (no table rewrite, no default backfill) and completes near-instantly; no downtime expected. MySQL 8 performs this as an INSTANT add for a nullable column.

Made with Cursor

Add a nullable `extra` column to the `slices` table and the `Slice`
model to store open-ended, structured chart metadata, mirroring the
existing dataset `extra` pattern. Uses `MediumText` for cross-backend
consistency and to avoid MySQL's 64KB TEXT limit, and includes the
field in chart import/export.

Ref: SIP apache#41171
Co-authored-by: Cursor <cursoragent@cursor.com>
@bito-code-review

bito-code-review Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6c6e4b

Actionable Suggestions - 0
Filtered by Review Rules

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

  • superset/migrations/versions/2026-06-17_16-58_9d4b2e8c1f0a_add_extra_column_to_slices.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: 897c634..897c634
    • superset/migrations/versions/2026-06-17_16-58_9d4b2e8c1f0a_add_extra_column_to_slices.py
    • superset/models/slice.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

@dosubot dosubot Bot added the change:backend Requires changing the backend label Jun 18, 2026
@github-actions github-actions Bot added the risk:db-migration PRs that require a DB migration label Jun 18, 2026
@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 897c634
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a34049090bb6000088ba33a
😎 Deploy Preview https://deploy-preview-41200--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 Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.33%. Comparing base (c218dc4) to head (2133aa4).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #41200   +/-   ##
=======================================
  Coverage   64.33%   64.33%           
=======================================
  Files        2651     2651           
  Lines      144766   144768    +2     
  Branches    33401    33401           
=======================================
+ Hits        93131    93133    +2     
  Misses      49965    49965           
  Partials     1670     1670           
Flag Coverage Δ
hive 39.33% <100.00%> (+<0.01%) ⬆️
mysql 58.06% <100.00%> (+<0.01%) ⬆️
postgres 58.13% <100.00%> (+<0.01%) ⬆️
presto 40.91% <100.00%> (+<0.01%) ⬆️
python 59.57% <100.00%> (+<0.01%) ⬆️
sqlite 57.79% <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 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.

Comment thread superset/models/slice.py
viz_type = Column(String(250))
params = Column(utils.MediumText())
query_context = Column(utils.MediumText())
extra = Column(utils.MediumText())

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: The new chart metadata field is persisted on the model but not copied when charts are cloned, so dashboard duplication will silently drop extra metadata on the duplicated charts. Update the chart cloning path to include this new field so cloned charts preserve the same metadata as the source chart. [incomplete implementation]

Severity Level: Major ⚠️
- ⚠️ Dashboard copy with duplicate charts drops chart extra metadata.
- ⚠️ Cloned charts diverge from originals in stored configuration.
Steps of Reproduction ✅
1. In a running Superset instance with this PR applied, pick an existing dashboard with
charts and ensure at least one chart has `Slice.extra` set (e.g. via a shell or test
fixture): `original_slc.extra = '{"foo": "bar"}'` for a `Slice` instance attached to a
dashboard. The `Slice` model (including the new `extra` column) is defined in
`superset/models/slice.py:17-27` as seen in the class definition.

2. Trigger a dashboard copy operation with chart duplication enabled. In production this
is done via the dashboard copy API which uses `CopyDashboardCommand`
(`superset/commands/dashboard/copy.py:6-15`) and `DashboardDAO.copy_dashboard`. In tests
the same path is exercised directly in
`superset/tests/integration_tests/dashboards/dao_tests.py:27-42`, where
`DashboardDAO.copy_dashboard(original_dash, dash_data)` is called with
`dash_data["duplicate_slices"] = True`.

3. During the copy operation, `DashboardDAO.copy_dashboard` in
`superset/daos/dashboard.py:368-46` iterates over `original_dash.slices` and, when
`duplicate_slices` is true, calls `new_slice = slc.clone()` at line 386 for each chart,
then adds each `new_slice` to the session and associates it with the new dashboard.

4. The `Slice.clone` method in `superset/models/slice.py:151-42` constructs a new `Slice`
with only `slice_name`, `datasource_id`, `datasource_type`, `datasource_name`, `viz_type`,
`params`, `description`, and `cache_timeout`, and does not copy the `extra` field. As a
result, each cloned chart's `extra` column remains NULL/empty even though the source
chart's `extra` contained metadata, so the duplicated dashboard's charts silently lose
their `extra` metadata.

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:** superset/models/slice.py
**Line:** 85:85
**Comment:**
	*Incomplete Implementation: The new chart metadata field is persisted on the model but not copied when charts are cloned, so dashboard duplication will silently drop `extra` metadata on the duplicated charts. Update the chart cloning path to include this new field so cloned charts preserve the same metadata as the source chart.

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
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The Slice.clone method (which is not visible in the provided diff but is referenced in the reproduction steps) needs to be updated to include the extra field in the dictionary of attributes copied from the source slice to the new slice.

To resolve this, locate the clone method in superset/models/slice.py and add extra to the attributes being copied:

# In superset/models/slice.py, inside the clone() method:
new_slice = Slice(
    slice_name=self.slice_name,
    # ... existing fields ...
    extra=self.extra,
    # ...
)

There are no other comments on this PR to address.

superset/models/slice.py

new_slice = Slice(
    slice_name=self.slice_name,
    # ... existing fields ...
    extra=self.extra,
    # ...
)

Adding `extra` to `Slice.export_fields` changes the chart export YAML,
so update the export command test expectations (metadata dict and key
order). Also accept `extra` in `ImportV1ChartSchema` so export->import
round-trips, and copy `extra` in `Slice.clone()` so duplicated charts
(e.g. dashboard copy) preserve the metadata.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bito-code-review

bito-code-review Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #94803f

Actionable Suggestions - 0
Filtered by Review Rules

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

  • superset/models/slice.py - 1
Review Details
  • Files reviewed - 3 · Commit Range: 897c634..2133aa4
    • superset/charts/schemas.py
    • superset/models/slice.py
    • tests/integration_tests/charts/commands_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

change:backend Requires changing the backend hold:sip! risk:db-migration PRs that require a DB migration size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants