codeant-ai-for-open-source[bot] commented on code in PR #40127:
URL: https://github.com/apache/superset/pull/40127#discussion_r3244503233
##########
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py:
##########
@@ -316,6 +333,46 @@ def _ensure_layout_structure(
layout["DASHBOARD_VERSION_KEY"] = "v2"
+def _resolve_parent_container(
+ layout: Dict[str, Any],
+ dashboard_id: int,
+ target_tab: str | None,
+) -> tuple[str, None] | tuple[None, AddChartToDashboardResponse]:
+ """Return (parent_id, None) on success or (None, error_response) on
mismatch.
+
+ When *target_tab* is specified and not found the caller receives a
+ descriptive error listing available tabs rather than a silent fallback.
+ """
+ tab_target = _find_tab_insert_target(layout, target_tab=target_tab)
+
+ if target_tab and tab_target is None:
Review Comment:
**Suggestion:** The mismatch check uses a truthiness test, so an explicitly
provided empty `target_tab` (`""`) is treated as "not provided" and silently
falls back to the first/default container instead of returning a tab-not-found
error. Check `target_tab is not None` (and optionally strip/validate blanks) so
any explicitly passed value follows the new "error on mismatch" behavior.
[incorrect condition logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Charts may be added to unintended tabs without error.
- ⚠️ Invalid target_tab inputs not surfaced to MCP callers.
- ⚠️ Behavior contradicts documented error-on-mismatch contract.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Construct an `AddChartToDashboardRequest` with `target_tab` explicitly
set to the empty
string `""` (see `superset/mcp_service/dashboard/schemas.py:462-470`, where
`target_tab:
str | None` is defined) and `dashboard_id` pointing to a dashboard that
either has tabs or
no tabs.
2. Call the MCP tool entrypoint `add_chart_to_existing_dashboard(request,
ctx)` in
`superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py:167-169`,
which
parses `dashboard.position_json` and then calls
`_resolve_parent_container(current_layout,
request.dashboard_id, request.target_tab)` at lines 238-241.
3. Inside `_resolve_parent_container`
(`add_chart_to_existing_dashboard.py:336-114`),
`_find_tab_insert_target(layout, target_tab=target_tab)` is invoked at line
346. Because
`target_tab == ""` is falsy, `_find_tab_insert_target` (lines 165-193) skips
the matching
branch `if target_tab:` and falls through to `_first_tab_from_groups(layout,
groups)` at
line 193, returning the first tab ID (when tabs exist) or `None` (when no
tabs exist).
4. Back in `_resolve_parent_container`, the mismatch check `if target_tab
and tab_target
is None:` at line 348 also treats `target_tab == ""` as falsy, so the error
branches that
construct an `AddChartToDashboardResponse` with a descriptive tab-not-found
error (lines
89-112) are never executed. Instead, the function returns `tab_target if
tab_target else
"GRID_ID", None` at line 114, silently placing the chart in the first tab or
the default
grid even though an explicit (but invalid/empty) `target_tab` value was
supplied. This
contradicts the documented behavior in
`AddChartToDashboardRequest.target_tab`
(schemas.py:20-28), which says a specified tab that is not found should
cause an error,
not a silent fallback.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmcp_service%2Fdashboard%2Ftool%2Fadd_chart_to_existing_dashboard.py%0A%2A%2ALine%3A%2A%2A%20348%3A348%0A%2A%2AComment%3A%2A%2A%0A%09%2AIncorrect%20Condition%20Logic%3A%20The%20mismatch%20check%20uses%20a%20truthiness%20test%2C%20so%20an%20explicitly%20provided%20empty%20%60target_tab%60%20%28%60%22%22%60%29%20is%20treated%20as%20%22not%20provided%22%20and%20silently%20falls%20back%20to%20the%20first%2Fdefault%20container%20instead%20of%20returning%20a%20tab-not-found%20error.%20Check%20%60target_tab%20is%20not%20None%60%20%28and%20optionally%20strip%2Fvalidate%20blanks%29%20so%20any%20explicitly%20passed%20value%20follows%20the%20new%20%22error%20on%20mismatch%22%20behavior.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%
20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmcp_service%2Fdashboard%2Ftool%2Fadd_chart_to_existing_dashboard.py%0A%2A%2ALine%3A%2A%2A%20348%3A348%0A%2A%2AComment%3A%2A%2A%0A%09%2AIncorrect%20Condition%20Logic%3A%20The%20mismatch%20check%20uses%20a%20truthiness%20test%2C%20so%20an%20explicitly%20provided%20empty%20%60target_tab%60%20%28%60%22%22%60%29%20is%20treated%20as%20%22not%20provided%22%20and%20silently%20falls%20back%20to%20the%20first%2Fdefault%20con
tainer%20instead%20of%20returning%20a%20tab-not-found%20error.%20Check%20%60target_tab%20is%20not%20None%60%20%28and%20optionally%20strip%2Fvalidate%20blanks%29%20so%20any%20explicitly%20passed%20value%20follows%20the%20new%20%22error%20on%20mismatch%22%20behavior.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
*(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/dashboard/tool/add_chart_to_existing_dashboard.py
**Line:** 348:348
**Comment:**
*Incorrect Condition Logic: The mismatch check uses a truthiness test,
so an explicitly provided empty `target_tab` (`""`) is treated as "not
provided" and silently falls back to the first/default container instead of
returning a tab-not-found error. Check `target_tab is not None` (and optionally
strip/validate blanks) so any explicitly passed value follows the new "error on
mismatch" behavior.
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%2F40127&comment_hash=288010537e2be19a61d95dbe4c3acaf80c3ceba727d74b4a48453d2705b796ed&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40127&comment_hash=288010537e2be19a61d95dbe4c3acaf80c3ceba727d74b4a48453d2705b796ed&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]