codeant-ai-for-open-source[bot] commented on code in PR #44338:
URL: https://github.com/apache/superset/pull/44338#discussion_r4023722038
##########
superset/mcp_service/chart/tool/get_chart_info.py:
##########
@@ -86,6 +91,106 @@ def _build_unsaved_chart_info(form_data_key: str) ->
ChartInfo | ChartError:
)
+def _get_explore_permalink(
+ permalink_key: str,
+) -> ExplorePermalinkValue | ChartError:
+ """Read an Explore permalink, enforcing the same access checks as Explore.
+
+ ``GetExplorePermalinkCommand`` checks access to the permalink's datasource
+ and, when it references a saved chart, to that chart.
+ """
+ from superset.commands.explore.permalink.get import
GetExplorePermalinkCommand
+
+ try:
+ value = GetExplorePermalinkCommand(permalink_key).run()
+ except ForbiddenError:
+ return ChartError(
+ error="You do not have access to the chart or dataset in this
permalink.",
+ error_type="PermalinkAccessDenied",
+ )
+ except (CommandException, SQLAlchemyError, ValidationError, ValueError) as
ex:
Review Comment:
**Suggestion:** `GetExplorePermalinkCommand` converts template failures into
`SupersetTemplateException`, which escapes this handler and causes an unhandled
MCP tool failure. [possible bug]
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b597d0b0514d43c8b3589abc3bfb5051&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b597d0b0514d43c8b3589abc3bfb5051&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<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/get_chart_info.py
**Line:** 111:111
**Comment:**
*Possible Bug: `GetExplorePermalinkCommand` converts template failures
into `SupersetTemplateException`, which escapes this handler and causes an
unhandled MCP tool failure.
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%2F44338&comment_hash=35a6ad88d06f46f0f4a513b3f795b60f4a9ebbb0a7117a6c24c24ccb282e1746&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44338&comment_hash=35a6ad88d06f46f0f4a513b3f795b60f4a9ebbb0a7117a6c24c24ccb282e1746&reaction=dislike'>๐</a>
##########
superset/mcp_service/chart/tool/get_chart_info.py:
##########
@@ -86,6 +91,106 @@ def _build_unsaved_chart_info(form_data_key: str) ->
ChartInfo | ChartError:
)
+def _get_explore_permalink(
+ permalink_key: str,
+) -> ExplorePermalinkValue | ChartError:
+ """Read an Explore permalink, enforcing the same access checks as Explore.
+
+ ``GetExplorePermalinkCommand`` checks access to the permalink's datasource
+ and, when it references a saved chart, to that chart.
+ """
+ from superset.commands.explore.permalink.get import
GetExplorePermalinkCommand
+
+ try:
+ value = GetExplorePermalinkCommand(permalink_key).run()
+ except ForbiddenError:
+ return ChartError(
+ error="You do not have access to the chart or dataset in this
permalink.",
+ error_type="PermalinkAccessDenied",
+ )
+ except (CommandException, SQLAlchemyError, ValidationError, ValueError) as
ex:
+ # ValidationError: the permalink's datasource no longer exists or has
an
+ # invalid type (raised by the access check).
+ logger.warning("Failed to read explore permalink: %s", ex)
+ return ChartError(
+ error="The explore permalink could not be read. Check the key.",
+ error_type="InvalidPermalink",
+ )
+ if not value:
+ return ChartError(
+ error="No explore permalink found for permalink_key.",
+ error_type="NotFound",
+ )
+ return value
+
+
+def _permalink_chart_id(permalink: ExplorePermalinkValue) -> int | None:
+ """Return the saved chart a permalink was created from, if any.
+
+ ``chartId`` is copied from the client-supplied ``formData.slice_id``, so
+ it is not guaranteed to be an int.
+ """
+ try:
+ return int(permalink.get("chartId") or 0) or None
+ except (TypeError, ValueError):
+ return None
+
+
+def _permalink_form_data(permalink: ExplorePermalinkValue) -> dict[str, Any]:
+ state = permalink.get("state")
+ form_data = state.get("formData") if isinstance(state, dict) else None
+ return dict(form_data) if isinstance(form_data, dict) else {}
Review Comment:
**Suggestion:** The reader drops `state.urlParams` and `state.chartState`,
so permalinks containing URL parameters or chart state return metadata
different from the Explore page. [api mismatch]
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6f14487bd7bf4e0497708e27a1cc3591&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6f14487bd7bf4e0497708e27a1cc3591&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<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/get_chart_info.py
**Line:** 140:142
**Comment:**
*Api Mismatch: The reader drops `state.urlParams` and
`state.chartState`, so permalinks containing URL parameters or chart state
return metadata different from the Explore page.
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%2F44338&comment_hash=fcaf3fbbed1ca41f2f60786d082e7d902f0cdea31301fdcc6e0a101fa5cd3475&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44338&comment_hash=fcaf3fbbed1ca41f2f60786d082e7d902f0cdea31301fdcc6e0a101fa5cd3475&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]