codeant-ai-for-open-source[bot] commented on code in PR #41923:
URL: https://github.com/apache/superset/pull/41923#discussion_r3562693635


##########
superset/mcp_service/chart/tool/generate_chart.py:
##########
@@ -886,14 +886,9 @@ async def generate_chart(  # noqa: C901
 
         logger.exception("Chart generation failed: %s", str(e))
 
-        # Extract chart_type from different sources for better error context
+        # request.config is always a validated ChartConfig (never a dict), so
+        # chart_type context isn't extractable here.
         chart_type = "unknown"

Review Comment:
   **Suggestion:** The exception path now hardcodes `chart_type` to `"unknown"` 
even though `request.config` is a validated `ChartConfig` with a real 
`chart_type`. This causes standardized error payloads to lose critical context 
and breaks downstream diagnostics/routing that rely on chart type in error 
metadata. Populate `chart_type` from `request.config.chart_type` (with a safe 
fallback only if unavailable) instead of always forcing `"unknown"`. [incorrect 
variable usage]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ❌ MCP generate_chart failures lose chart_type in details.
   ⚠️ LLM clients cannot branch on chart-type-specific diagnostics.
   ⚠️ Support sees generic "unknown chart" for all failures.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Construct a valid GenerateChartRequest with a real chart_type using
   superset/mcp_service/chart/schemas.py:1880-2099, e.g.
   config=TableChartConfig(chart_type="table"), as shown in tests at
   
superset/tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py:52-59.
   
   2. Call the MCP tool generate_chart(request, ctx) defined in
   superset/mcp_service/chart/tool/generate_chart.py:98-115 via the MCP service 
(documented
   in superset/mcp_service/app.py:107-118), so request.config is a validated 
ChartConfig
   union with a chart_type field.
   
   3. Trigger a runtime failure after validation (e.g. a CommandException or 
ValueError
   during chart creation or compile checks) so execution enters the generic 
exception handler
   at superset/mcp_service/chart/tool/generate_chart.py:30-52 in the last tool 
output, where
   chart_type is set to "unknown" instead of reading request.config.chart_type.
   
   4. Observe the structured error response built by 
ChartErrorBuilder.build_error at
   superset/mcp_service/chart/tool/generate_chart.py:57-66 and
   superset/mcp_service/utils/error_builder.py:178-186: the template details 
field becomes
   "Failed to create unknown chart for dataset <id>", proving that the real 
chart_type from
   request.config was available (used earlier at generate_chart.py:106-115) but 
is dropped
   and replaced with "unknown" in all generation_failed errors.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b46f919db56c478181a3ec216c8490f3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b46f919db56c478181a3ec216c8490f3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <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/generate_chart.py
   **Line:** 889:891
   **Comment:**
        *Incorrect Variable Usage: The exception path now hardcodes 
`chart_type` to `"unknown"` even though `request.config` is a validated 
`ChartConfig` with a real `chart_type`. This causes standardized error payloads 
to lose critical context and breaks downstream diagnostics/routing that rely on 
chart type in error metadata. Populate `chart_type` from 
`request.config.chart_type` (with a safe fallback only if unavailable) instead 
of always forcing `"unknown"`.
   
   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
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41923&comment_hash=e01fe4b3938257dc04f46edfc0e700055743796bcf87e9909a1670412e1b1497&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41923&comment_hash=e01fe4b3938257dc04f46edfc0e700055743796bcf87e9909a1670412e1b1497&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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to