bito-code-review[bot] commented on code in PR #44152:
URL: https://github.com/apache/superset/pull/44152#discussion_r3989638526


##########
superset/mcp_service/chart/tool/update_chart_preview.py:
##########
@@ -177,6 +178,39 @@ def update_chart_preview(  # noqa: C901
                 NORMALIZATION_EXCEPTIONS,
             )
 
+            warnings: list[str] = []
+            previous_form_data: dict[str, Any] | None = None
+
+            if request.form_data_key:
+                previous_form_data = 
_get_previous_form_data(request.form_data_key)
+                if previous_form_data is None:
+                    warnings.append(INVALID_FORM_DATA_KEY_WARNING)
+            previous_datasource = str(
+                (previous_form_data or {}).get("datasource")
+                or (previous_form_data or {}).get("datasource_id")
+                or ""
+            ).split("__", 1)[0]
+            dataset_rebind = previous_datasource != str(dataset.id) and (
+                bool(previous_datasource) or config.chart_type == "treemap_v2"
+            )
+            try:
+                config = resolve_treemap_update_config(
+                    config,
+                    previous_form_data or {},
+                    dataset_rebind=dataset_rebind,
+                )
+            except ValueError as ex:
+                return {
+                    "chart": None,
+                    "error": {
+                        "error_type": "ValidationError",
+                        "message": "Invalid Treemap update configuration",
+                        "details": str(ex),
+                    },
+                    "success": False,
+                    "schema_version": "2.0",
+                    "api_version": "v1",
+                }

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Uncaught pydantic ValidationError</b></div>
   <div id="fix">
   
   `resolve_treemap_update_config` calls `TreemapChartConfig.model_validate` 
(chart_utils.py:692), which raises pydantic v2 `ValidationError` on invalid 
config. That exception is not a subclass of `ValueError`, so this handler never 
fires and the structured error is never returned; the `ValidationError` also 
isn't in the outer `except` tuple (lines 426-434), so the tool fails with an 
unhandled exception. Catch `(ValueError, ValidationError)`.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
               dataset_rebind = previous_datasource != str(dataset.id) and (
                   bool(previous_datasource) or config.chart_type == 
"treemap_v2"
               )
               from pydantic import ValidationError
               try:
                   config = resolve_treemap_update_config(
                       config,
                       previous_form_data or {},
                       dataset_rebind=dataset_rebind,
                   )
               except (ValueError, ValidationError) as ex:
                   return {
                       "chart": None,
                       "error": {
                           "error_type": "ValidationError",
                           "message": "Invalid Treemap update configuration",
                           "details": str(ex),
                       },
                       "success": False,
                       "schema_version": "2.0",
                       "api_version": "v1",
                   }
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #e5f050</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]

Reply via email to