bito-code-review[bot] commented on code in PR #37183:
URL: https://github.com/apache/superset/pull/37183#discussion_r2696368153
##########
superset/mcp_service/chart/tool/get_chart_data.py:
##########
@@ -42,6 +42,22 @@
logger = logging.getLogger(__name__)
+def _get_cached_form_data(form_data_key: str) -> str | None:
+ """Retrieve form_data from cache using form_data_key.
+
+ Returns the JSON string of form_data if found, None otherwise.
+ """
+ from superset.commands.explore.form_data.get import GetFormDataCommand
+ from superset.commands.explore.form_data.parameters import
CommandParameters
+
+ try:
+ cmd_params = CommandParameters(key=form_data_key)
+ return GetFormDataCommand(cmd_params).run()
+ except Exception as e:
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Blind exception catch without specific type</b></div>
<div id="fix">
Replace bare `Exception` catch with specific exception types. Consider
catching `(KeyError, ValueError, TypeError)` or other specific exceptions
expected from `GetFormDataCommand.run()`.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
except (KeyError, ValueError, TypeError) as e:
````
</div>
</details>
</div>
<small><i>Code Review Run #d14d53</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/mcp_service/chart/tool/get_chart_info.py:
##########
@@ -36,6 +36,22 @@
logger = logging.getLogger(__name__)
+def _get_cached_form_data(form_data_key: str) -> str | None:
+ """Retrieve form_data from cache using form_data_key.
+
+ Returns the JSON string of form_data if found, None otherwise.
+ """
+ from superset.commands.explore.form_data.get import GetFormDataCommand
+ from superset.commands.explore.form_data.parameters import
CommandParameters
+
+ try:
+ cmd_params = CommandParameters(key=form_data_key)
+ return GetFormDataCommand(cmd_params).run()
+ except Exception as e:
+ logger.warning("Failed to retrieve form_data from cache: %s", e)
+ return None
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Blind exception catch too broad</b></div>
<div id="fix">
Avoid catching bare `Exception` at line 50. Catch specific exception types
(e.g., `KeyError`, `ValueError`) to improve error handling clarity and prevent
masking unexpected errors.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
try:
cmd_params = CommandParameters(key=form_data_key)
return GetFormDataCommand(cmd_params).run()
except (KeyError, ValueError) as e:
logger.warning("Failed to retrieve form_data from cache: %s", e)
return None
````
</div>
</details>
</div>
<small><i>Code Review Run #d14d53</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/mcp_service/dashboard/tool/get_dashboard_info.py:
##########
@@ -40,6 +41,23 @@
logger = logging.getLogger(__name__)
+def _get_permalink_state(permalink_key: str) -> Dict[str, Any] | None:
+ """Retrieve dashboard filter state from permalink.
+
+ Returns the permalink value containing dashboardId and state if found,
+ None otherwise.
+ """
+ from superset.commands.dashboard.permalink.get import
GetDashboardPermalinkCommand
+
+ try:
+ result = GetDashboardPermalinkCommand(permalink_key).run()
+ # Convert TypedDict to regular dict for type compatibility
+ return dict(result) if result else None
+ except Exception as e:
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Blind exception catch too broad</b></div>
<div id="fix">
Replace bare `Exception` catch with specific exception types (e.g.,
`Exception` from the command or `ValueError`). This prevents masking unexpected
errors.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
except (ValueError, KeyError, Exception) as e:
````
</div>
</details>
</div>
<small><i>Code Review Run #d14d53</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/mcp_service/chart/tool/get_chart_info.py:
##########
@@ -83,9 +111,41 @@ async def get_chart_info(
result = tool.run_tool(request.identifier)
if isinstance(result, ChartInfo):
+ # If form_data_key is provided, override form_data with cached version
+ if request.form_data_key:
+ await ctx.info(
+ "Retrieving unsaved chart state from cache: form_data_key=%s"
+ % (request.form_data_key,)
+ )
+ cached_form_data = _get_cached_form_data(request.form_data_key)
+
+ if cached_form_data:
+ try:
+ result.form_data = utils_json.loads(cached_form_data)
+ result.form_data_key = request.form_data_key
+ result.is_unsaved_state = True
+
+ # Update viz_type from cached form_data if present
+ if result.form_data and "viz_type" in result.form_data:
+ result.viz_type = result.form_data["viz_type"]
+
+ await ctx.info(
+ "Chart form_data overridden with unsaved state from
cache"
+ )
+ except Exception as e:
+ await ctx.warning(
+ "Failed to parse cached form_data: %s. "
+ "Using saved chart configuration." % (str(e),)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Blind exception catch too broad</b></div>
<div id="fix">
Avoid catching bare `Exception` at line 135. Catch specific exception types
(e.g., `json.JSONDecodeError`, `ValueError`) to improve error handling clarity.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
await ctx.info(
"Chart form_data overridden with unsaved state from
cache"
)
except (ValueError, TypeError) as e:
await ctx.warning(
"Failed to parse cached form_data: %s. "
"Using saved chart configuration." % (str(e),)
````
</div>
</details>
</div>
<small><i>Code Review Run #d14d53</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]