You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by as...@apache.org on 2026/04/27 11:29:33 UTC
(superset) 01/01: fix(key): make cached key optional for chart preview
This is an automated email from the ASF dual-hosted git repository.
alexandrusoare pushed a commit to branch alexandrusoare/fix/preview_chart_optional_key
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 151f1a81815be5121430b89ce4fcf974a7789138
Author: alexandrusoare <al...@gmail.com>
AuthorDate: Mon Apr 27 14:29:00 2026 +0300
fix(key): make cached key optional for chart preview
---
superset/mcp_service/chart/schemas.py | 8 +++++++-
.../mcp_service/chart/tool/update_chart_preview.py | 7 +++----
.../chart/tool/test_update_chart_preview.py | 18 ++++++++++++++++++
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/superset/mcp_service/chart/schemas.py b/superset/mcp_service/chart/schemas.py
index 2323c10232a..ab142096b92 100644
--- a/superset/mcp_service/chart/schemas.py
+++ b/superset/mcp_service/chart/schemas.py
@@ -1574,7 +1574,13 @@ class UpdateChartRequest(QueryCacheControl):
class UpdateChartPreviewRequest(FormDataCacheControl):
- form_data_key: str = Field(..., description="Existing form_data_key to update")
+ form_data_key: str | None = Field(
+ None,
+ description=(
+ "Existing form_data_key to update"
+ " (omit for fresh preview from config + dataset_id)"
+ ),
+ )
dataset_id: int | str = Field(..., description="Dataset ID or UUID")
config: Dict[str, Any] = Field(..., description=_CHART_CONFIG_DESCRIPTION)
generate_preview: bool = True
diff --git a/superset/mcp_service/chart/tool/update_chart_preview.py b/superset/mcp_service/chart/tool/update_chart_preview.py
index 1c2eba5580b..38b7a5abfdc 100644
--- a/superset/mcp_service/chart/tool/update_chart_preview.py
+++ b/superset/mcp_service/chart/tool/update_chart_preview.py
@@ -90,14 +90,13 @@ def update_chart_preview(
"""Update cached chart preview without saving.
IMPORTANT:
- - Modifies cached form_data from generate_chart (save_chart=False)
- - Original form_data_key is invalidated, new one returned
+ - Original form_data_key (when provided) is invalidated, new one returned
- LLM clients MUST display explore_url to users
Use when:
- - Modifying preview before deciding to save
+ - Creating a fresh preview from config + dataset_id (omit form_data_key)
+ - Modifying an existing preview before deciding to save
- Iterating on chart design without creating permanent charts
- - Testing different configurations
Returns new form_data_key, preview images, and explore URL.
"""
diff --git a/tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py b/tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py
index c80f2797a47..691fe3eb169 100644
--- a/tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py
+++ b/tests/unit_tests/mcp_service/chart/tool/test_update_chart_preview.py
@@ -374,6 +374,24 @@ class TestUpdateChartPreview:
)
assert request.form_data_key == key
+ @pytest.mark.asyncio
+ async def test_update_chart_preview_form_data_key_optional(self):
+ """Test that form_data_key can be omitted for fresh previews."""
+ config = TableChartConfig(
+ chart_type="table",
+ columns=[ColumnRef(name="col1")],
+ )
+
+ # Omit form_data_key entirely
+ request = UpdateChartPreviewRequest(dataset_id=1, config=config)
+ assert request.form_data_key is None
+
+ # Explicitly pass None
+ request2 = UpdateChartPreviewRequest(
+ form_data_key=None, dataset_id=1, config=config
+ )
+ assert request2.form_data_key is None
+
@pytest.mark.asyncio
async def test_update_chart_preview_cache_control(self):
"""Test cache control parameters in update preview request."""