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


##########
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:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > For get_chart_info, treat permalink form_data as the chart definition; do 
not include urlParams or chartState in chart metadata, as they are separate 
Explore URL and visualization interaction state.
   
   **Applied to:**
     - `superset/mcp_service/chart/tool/get_chart_info.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



-- 
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