codeant-ai-for-open-source[bot] commented on code in PR #38409:
URL: https://github.com/apache/superset/pull/38409#discussion_r2894943678
##########
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py:
##########
@@ -63,35 +63,107 @@ def _find_next_row_position(layout: Dict[str, Any]) -> str:
return row_key
-def _find_tab_insert_target(layout: Dict[str, Any]) -> str | None:
+def _normalize_tab_text(text: str) -> str:
+ """Strip emoji and extra whitespace from tab text for flexible matching."""
+ import re
+
+ # Remove emoji characters (Unicode emoji ranges)
Review Comment:
**Suggestion:** If a tab's `meta.text` value is `null` in the stored JSON
(which becomes `None` after `json.loads`), `_match_tab_in_children` will pass
`None` into `_normalize_tab_text`, causing `re.sub` to raise a `TypeError` and
breaking the tool for those dashboards; adding a small guard in
`_normalize_tab_text` to handle `None` avoids this runtime failure without
changing behavior for valid strings. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ MCP add_chart_to_existing_dashboard crashes for dashboards with null tab
text.
- ⚠️ Users cannot programmatically add charts to affected tabbed dashboards.
```
</details>
```suggestion
if text is None:
return ""
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Start Superset with this PR code and ensure MCP tools are enabled so
`add_chart_to_existing_dashboard` in
`superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py` is
callable.
2. Create or modify a dashboard whose `position_json` (loaded in
`add_chart_to_existing_dashboard` around the layout parsing block) contains
a TAB
component under `ROOT_ID` or `GRID_ID` whose JSON has `"meta": {"text":
null}`; after
`json.loads` this becomes `meta["text"] is None`.
3. Invoke the MCP tool `add_chart_to_existing_dashboard` with a non-empty
`target_tab` (so
`_find_tab_insert_target` at ~line 140 is called with `target_tab` and
`_collect_tabs_groups` at lines 107–125 finds the TABS group containing the
TAB whose
`meta.text` is `None`).
4. During the loop in `_match_tab_in_children` at lines 82–104, `tab_text`
is set to
`None`, then `_normalize_tab_text(tab_text)` at line 102 calls `re.sub(...,
text=None)`
(function at lines 66–79), causing `TypeError: expected string or bytes-like
object`; this
bubbles up to the outer `except` in `add_chart_to_existing_dashboard`, which
logs an error
and returns an `AddChartToDashboardResponse` with `error="Failed to add
chart to
dashboard: expected string or bytes-like object"`.
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py
**Line:** 70:70
**Comment:**
*Type Error: If a tab's `meta.text` value is `null` in the stored JSON
(which becomes `None` after `json.loads`), `_match_tab_in_children` will pass
`None` into `_normalize_tab_text`, causing `re.sub` to raise a `TypeError` and
breaking the tool for those dashboards; adding a small guard in
`_normalize_tab_text` to handle `None` avoids this runtime failure without
changing behavior for valid strings.
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%2F38409&comment_hash=0fa1a00d800516e2d1a24796bf53056addabfe53bcbc494db5f4c4daba88d479&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38409&comment_hash=0fa1a00d800516e2d1a24796bf53056addabfe53bcbc494db5f4c4daba88d479&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]