You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2026/04/04 16:52:56 UTC

[PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

aminghadersohi opened a new pull request, #39109:
URL: https://github.com/apache/superset/pull/39109

   ## Summary
   
   Four bugs discovered during MCP eval suite testing:
   
   ### 1. get_chart_info returns form_data=null (sc-103137)
   `serialize_chart_object()` never populated the `form_data` field from the chart's `params` JSON. Now parses `chart.params` and includes it in the response so LLMs can understand chart configuration.
   
   ### 2. get_dataset_info returns relative URL (sc-103138)
   Dataset URLs were relative (`/tablemodelview/edit/1`) instead of absolute. Now uses `get_superset_base_url()` to construct absolute URLs, matching the pattern used by chart and dashboard serializers.
   
   ### 3. ASCII preview crashes with "Columns missing" (sc-103139)
   When a chart's form_data has no `groupby`, `x_axis`, or `all_columns` fields, the ASCII preview passed an empty columns list to `QueryContextFactory`, causing a crash. Now returns a clear `UnsupportedChart` error.
   
   ### 4. update_chart requires config for rename (sc-103140)
   `UpdateChartRequest.config` was required even for name-only updates. Now optional — users can rename a chart with just `{identifier: 123, chart_name: "New Name"}`. Extracted `_find_chart()` and `_build_update_payload()` helpers to keep complexity under C901 threshold.
   
   ### Testing
   - ruff format + check clean
   - All changes in `superset/mcp_service/`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #39109:
URL: https://github.com/apache/superset/pull/39109#issuecomment-4187405107

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/39109?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `10.81081%` with `33 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 54.58%. Comparing base ([`d796543`](https://app.codecov.io/gh/apache/superset/commit/d796543f5a0c5f6306f3140d48647640b7a28a14?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`eb4e7f4`](https://app.codecov.io/gh/apache/superset/commit/eb4e7f42401c3e8179fe32eca39a150706bc0508?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/39109?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/mcp\_service/chart/tool/update\_chart.py](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fupdate_chart.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC91cGRhdGVfY2hhcnQucHk=) | 13.04% | [20 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/chart/schemas.py](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Fschemas.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvc2NoZW1hcy5weQ==) | 9.09% | [10 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...perset/mcp\_service/chart/tool/get\_chart\_preview.py](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fget_chart_preview.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC9nZXRfY2hhcnRfcHJldmlldy5weQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/dataset/schemas.py](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdataset%2Fschemas.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGF0YXNldC9zY2hlbWFzLnB5) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (d796543) and HEAD (eb4e7f4). Click for more details.
   > 
   > <details><summary>HEAD has 119 uploads less than BASE</summary>
   >
   >| Flag | BASE (d796543) | HEAD (eb4e7f4) |
   >|------|------|------|
   >|python|110|1|
   >|presto|11|1|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #39109      +/-   ##
   ==========================================
   - Coverage   64.52%   54.58%   -9.95%     
   ==========================================
     Files        2536     2536              
     Lines      131208   131231      +23     
     Branches    30457    30463       +6     
   ==========================================
   - Hits        84661    71626   -13035     
   - Misses      45084    59266   +14182     
   + Partials     1463      339    -1124     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.04% <10.81%> (-0.02%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.04% <10.81%> (-22.50%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/39109/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/39109?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi merged PR #39109:
URL: https://github.com/apache/superset/pull/39109


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #39109:
URL: https://github.com/apache/superset/pull/39109#discussion_r3040424533


##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -46,6 +47,62 @@
 logger = logging.getLogger(__name__)
 
 
+def _find_chart(identifier: int | str) -> Any | None:
+    """Find a chart by numeric ID or UUID string."""
+    from superset.daos.chart import ChartDAO
+
+    if isinstance(identifier, int) or (
+        isinstance(identifier, str) and identifier.isdigit()
+    ):
+        chart_id = int(identifier) if isinstance(identifier, str) else identifier
+        return ChartDAO.find_by_id(chart_id)
+    return ChartDAO.find_by_id(identifier, id_column="uuid")
+
+
+def _build_update_payload(
+    request: UpdateChartRequest,
+    chart: Any,
+) -> dict[str, Any] | GenerateChartResponse:
+    """Build the update payload for a chart update.
+
+    Returns a dict payload on success, or a GenerateChartResponse error
+    when neither config nor chart_name is provided.
+    """
+    if request.config is not None:
+        dataset_id = chart.datasource_id if chart.datasource_id else None
+        new_form_data = map_config_to_form_data(request.config, dataset_id=dataset_id)
+        new_form_data.pop("_mcp_warnings", None)
+
+        chart_name = (
+            request.chart_name
+            if request.chart_name
+            else chart.slice_name or generate_chart_name(request.config)
+        )
+
+        return {
+            "slice_name": chart_name,
+            "viz_type": new_form_data["viz_type"],
+            "params": json.dumps(new_form_data),
+        }
+
+    # Name-only update: keep existing visualization, just rename
+    if not request.chart_name:
+        return GenerateChartResponse.model_validate(
+            {
+                "chart": None,
+                "error": (
+                    "Either 'config' or 'chart_name' must be provided. "
+                    "Use config for visualization changes, chart_name "
+                    "for renaming."
+                ),
+                "success": False,
+                "schema_version": "2.0",
+                "api_version": "v1",
+            }
+        )

Review Comment:
   Fixed in commit 05bfee18. All three error returns now use structured `ChartGenerationError` dicts: NotFound (line 173), ValidationError (line 93), and dynamic error_type in exception handler (line 330).



##########
superset/mcp_service/chart/schemas.py:
##########
@@ -1284,7 +1296,13 @@ class GenerateExploreLinkRequest(FormDataCacheControl):
 
 class UpdateChartRequest(QueryCacheControl):
     identifier: int | str = Field(..., description="Chart ID or UUID")
-    config: ChartConfig
+    config: ChartConfig | None = Field(
+        None,
+        description=(
+            "Chart configuration. Required for visualization changes. "
+            "Omit to only update the chart name."
+        ),
+    )

Review Comment:
   Tests added in commit 05bfee18 and cde34cd4:
   - `TestBuildUpdatePayload.test_name_only_update` — name-only rename returns dict payload
   - `TestBuildUpdatePayload.test_no_config_no_name_error` — neither config nor name returns ValidationError
   - `TestBuildUpdatePayload.test_config_update_uses_request_chart_name` — config + name uses provided name
   - `TestBuildUpdatePayload.test_config_update_keeps_existing_name` — config without name keeps existing
   - `TestUpdateChartNameOnly.test_name_only_update_success` — integration test via MCP Client
   - `TestUpdateChartNameOnly.test_no_config_no_name_returns_error` — integration error test



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #39109:
URL: https://github.com/apache/superset/pull/39109#discussion_r3035797930


##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -46,6 +47,62 @@
 logger = logging.getLogger(__name__)
 
 
+def _find_chart(identifier: int | str) -> Any | None:
+    """Find a chart by numeric ID or UUID string."""
+    from superset.daos.chart import ChartDAO
+
+    if isinstance(identifier, int) or (
+        isinstance(identifier, str) and identifier.isdigit()
+    ):
+        chart_id = int(identifier) if isinstance(identifier, str) else identifier
+        return ChartDAO.find_by_id(chart_id)
+    return ChartDAO.find_by_id(identifier, id_column="uuid")
+
+
+def _build_update_payload(
+    request: UpdateChartRequest,
+    chart: Any,
+) -> dict[str, Any] | GenerateChartResponse:
+    """Build the update payload for a chart update.
+
+    Returns a dict payload on success, or a GenerateChartResponse error
+    when neither config nor chart_name is provided.
+    """
+    if request.config is not None:
+        dataset_id = chart.datasource_id if chart.datasource_id else None
+        new_form_data = map_config_to_form_data(request.config, dataset_id=dataset_id)
+        new_form_data.pop("_mcp_warnings", None)
+
+        chart_name = (
+            request.chart_name
+            if request.chart_name
+            else chart.slice_name or generate_chart_name(request.config)
+        )
+
+        return {
+            "slice_name": chart_name,
+            "viz_type": new_form_data["viz_type"],
+            "params": json.dumps(new_form_data),
+        }
+
+    # Name-only update: keep existing visualization, just rename
+    if not request.chart_name:
+        return GenerateChartResponse.model_validate(
+            {
+                "chart": None,
+                "error": (
+                    "Either 'config' or 'chart_name' must be provided. "
+                    "Use config for visualization changes, chart_name "
+                    "for renaming."

Review Comment:
   **Suggestion:** `GenerateChartResponse.error` expects a structured `ChartGenerationError` object, but this branch passes a plain string. `model_validate()` will raise a validation error instead of returning a failure response, so requests without both `config` and `chart_name` can crash the tool path. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ update_chart MCP tool crashes when config and name missing.
   - ⚠️ LLM clients receive internal errors instead of structured validation feedback.
   - ⚠️ Reduces robustness of MCP-based chart update workflows.
   ```
   </details>
   
   ```suggestion
                   "error": {
                       "error_type": "ValidationError",
                       "message": "Either 'config' or 'chart_name' must be provided.",
                       "details": (
                           "Use config for visualization changes, chart_name "
                           "for renaming."
                       ),
                   },
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Note that `GenerateChartResponse.error` is typed as a `ChartGenerationError` in
   `superset/mcp_service/chart/schemas.py` (class `GenerateChartResponse`, field `error:
   ChartGenerationError | None`), while `ChartGenerationError` itself is a Pydantic model
   defined in `superset/mcp_service/common/error_schemas.py` with required fields
   `error_type`, `message`, and `details`.
   
   2. Start the Superset MCP service so that tools from `superset/mcp_service/app.py` are
   registered; the `get_default_instructions()` function lists `update_chart` as an available
   tool (lines 61–69), which is implemented by the async function `update_chart()` in
   `superset/mcp_service/chart/tool/update_chart.py:115-161`.
   
   3. From an MCP client (or a test harness), invoke the `update_chart` tool with an
   `UpdateChartRequest` where `identifier` points to an existing chart, but both `config` and
   `chart_name` are omitted or explicitly set to `null`, which is allowed by
   `UpdateChartRequest` in `superset/mcp_service/chart/schemas.py:10-21` (`config:
   ChartConfig | None = None`, `chart_name: str | None = None`).
   
   4. During this call, `update_chart()` (update_chart.py:164-186) successfully resolves the
   chart and then calls `_build_update_payload(request, chart)` (update_chart.py:62-65);
   because `request.config is None` and `request.chart_name` is falsy,
   `_build_update_payload` takes the branch at lines 88-102 and executes
   `GenerateChartResponse.model_validate({ "chart": None, "error": (<multi-line string>),
   "success": False, ... })` where the `error` value is a plain string (lines 93-96).
   Pydantic attempts to populate the `error: ChartGenerationError` field from this string,
   which does not match the expected object/dict input, raising a `ValidationError`. This
   validation error prevents a `GenerateChartResponse` instance from being returned and
   instead causes the `update_chart` tool call to fail with an internal exception instead of
   a structured failure response describing the missing `config`/`chart_name`.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/chart/tool/update_chart.py
   **Line:** 93:96
   **Comment:**
   	*Type Error: `GenerateChartResponse.error` expects a structured `ChartGenerationError` object, but this branch passes a plain string. `model_validate()` will raise a validation error instead of returning a failure response, so requests without both `config` and `chart_name` can crash the tool path.
   
   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.
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39109&comment_hash=2969b0723ca8d32d895a7851843de25bb2e0133a4a69db6cf613d45f402ec9de&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39109&comment_hash=2969b0723ca8d32d895a7851843de25bb2e0133a4a69db6cf613d45f402ec9de&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39109:
URL: https://github.com/apache/superset/pull/39109#issuecomment-4187519925

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39109:
URL: https://github.com/apache/superset/pull/39109#issuecomment-4187400625

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #39109:
URL: https://github.com/apache/superset/pull/39109#discussion_r3035798091


##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -46,6 +47,62 @@
 logger = logging.getLogger(__name__)
 
 
+def _find_chart(identifier: int | str) -> Any | None:
+    """Find a chart by numeric ID or UUID string."""
+    from superset.daos.chart import ChartDAO
+
+    if isinstance(identifier, int) or (
+        isinstance(identifier, str) and identifier.isdigit()
+    ):
+        chart_id = int(identifier) if isinstance(identifier, str) else identifier
+        return ChartDAO.find_by_id(chart_id)
+    return ChartDAO.find_by_id(identifier, id_column="uuid")
+
+
+def _build_update_payload(
+    request: UpdateChartRequest,
+    chart: Any,
+) -> dict[str, Any] | GenerateChartResponse:
+    """Build the update payload for a chart update.
+
+    Returns a dict payload on success, or a GenerateChartResponse error
+    when neither config nor chart_name is provided.
+    """
+    if request.config is not None:
+        dataset_id = chart.datasource_id if chart.datasource_id else None
+        new_form_data = map_config_to_form_data(request.config, dataset_id=dataset_id)
+        new_form_data.pop("_mcp_warnings", None)
+
+        chart_name = (
+            request.chart_name
+            if request.chart_name
+            else chart.slice_name or generate_chart_name(request.config)
+        )
+
+        return {
+            "slice_name": chart_name,
+            "viz_type": new_form_data["viz_type"],
+            "params": json.dumps(new_form_data),
+        }
+
+    # Name-only update: keep existing visualization, just rename
+    if not request.chart_name:
+        return GenerateChartResponse.model_validate(
+            {
+                "chart": None,
+                "error": (
+                    "Either 'config' or 'chart_name' must be provided. "
+                    "Use config for visualization changes, chart_name "
+                    "for renaming."
+                ),
+                "success": False,
+                "schema_version": "2.0",
+                "api_version": "v1",
+            }
+        )

Review Comment:
   `GenerateChartResponse.error` is typed as `ChartGenerationError | None` (see `chart/schemas.py`), but this error path builds a response with `error` as a plain string. `GenerateChartResponse.model_validate(...)` will fail validation here, and callers/tests expect a structured error object (with `error_type/message/details`). Return a properly shaped `ChartGenerationError` (or dict matching it) instead of a string for this failure case.



##########
superset/mcp_service/chart/schemas.py:
##########
@@ -1284,7 +1296,13 @@ class GenerateExploreLinkRequest(FormDataCacheControl):
 
 class UpdateChartRequest(QueryCacheControl):
     identifier: int | str = Field(..., description="Chart ID or UUID")
-    config: ChartConfig
+    config: ChartConfig | None = Field(
+        None,
+        description=(
+            "Chart configuration. Required for visualization changes. "
+            "Omit to only update the chart name."
+        ),
+    )

Review Comment:
   `UpdateChartRequest.config` is now optional to allow name-only updates, but there are existing unit tests for `update_chart` and none cover the new rename-only request shape (e.g. `{identifier, chart_name}` without `config`) or the error case when both `config` and `chart_name` are omitted. Add/adjust unit tests to lock in this new behavior and prevent regressions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): fix form_data null, dataset URL, ASCII preview, and chart rename [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #39109:
URL: https://github.com/apache/superset/pull/39109#discussion_r3040423445


##########
superset/mcp_service/chart/tool/update_chart.py:
##########
@@ -46,6 +47,62 @@
 logger = logging.getLogger(__name__)
 
 
+def _find_chart(identifier: int | str) -> Any | None:
+    """Find a chart by numeric ID or UUID string."""
+    from superset.daos.chart import ChartDAO
+
+    if isinstance(identifier, int) or (
+        isinstance(identifier, str) and identifier.isdigit()
+    ):
+        chart_id = int(identifier) if isinstance(identifier, str) else identifier
+        return ChartDAO.find_by_id(chart_id)
+    return ChartDAO.find_by_id(identifier, id_column="uuid")
+
+
+def _build_update_payload(
+    request: UpdateChartRequest,
+    chart: Any,
+) -> dict[str, Any] | GenerateChartResponse:
+    """Build the update payload for a chart update.
+
+    Returns a dict payload on success, or a GenerateChartResponse error
+    when neither config nor chart_name is provided.
+    """
+    if request.config is not None:
+        dataset_id = chart.datasource_id if chart.datasource_id else None
+        new_form_data = map_config_to_form_data(request.config, dataset_id=dataset_id)
+        new_form_data.pop("_mcp_warnings", None)
+
+        chart_name = (
+            request.chart_name
+            if request.chart_name
+            else chart.slice_name or generate_chart_name(request.config)
+        )
+
+        return {
+            "slice_name": chart_name,
+            "viz_type": new_form_data["viz_type"],
+            "params": json.dumps(new_form_data),
+        }
+
+    # Name-only update: keep existing visualization, just rename
+    if not request.chart_name:
+        return GenerateChartResponse.model_validate(
+            {
+                "chart": None,
+                "error": (
+                    "Either 'config' or 'chart_name' must be provided. "
+                    "Use config for visualization changes, chart_name "
+                    "for renaming."

Review Comment:
   Addressed in commit 05bfee18. All error paths now return structured `ChartGenerationError` dicts with `error_type`, `message`, and `details` fields instead of plain strings.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org