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


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -3783,6 +3784,32 @@ def chart_config_reference_schema(*, nullable: bool = 
False) -> WithJsonSchema:
 }
 
 
+def _normalize_chart_target_alias(data: dict[str, Any]) -> dict[str, Any]:
+    """Copy legacy target vocabulary without changing its datasource family."""
+    data = dict(data)
+    if "datasource_type" in data and (
+        (data.get("dataset_id") is not None and data["datasource_type"] != 
"table")
+        or (
+            data.get("view_id") is not None
+            and data["datasource_type"] != "semantic_view"
+        )
+    ):
+        raise ValueError("datasource_type conflicts with the explicit chart 
target")
+    if "datasource_id" in data:
+        source_type: object = data.get("datasource_type", "table")
+        if source_type not in ("table", "semantic_view"):
+            raise ValueError("datasource_type must be table or semantic_view")
+        target_key: str = "view_id" if source_type == "semantic_view" else 
"dataset_id"
+        other_key: str = "dataset_id" if target_key == "view_id" else "view_id"
+        source_id: object = data.pop("datasource_id")
+        if data.get(other_key) is not None or (
+            data.get(target_key) is not None and data[target_key] != source_id
+        ):
+            raise ValueError("datasource_id conflicts with the explicit chart 
target")
+        data[target_key] = source_id

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>CWE-20: Semantic Target Blocked</b></div>
   <div id="fix">
   
   The new translation maps `datasource_id`+`datasource_type: "semantic_view"` 
to `view_id` (schemas.py:3802,3809), but `SchemaValidator._pre_validate` 
(schema_validator.py:92-104) then rejects any request without `dataset_id` with 
"Missing required field: dataset_id", suggesting `list_datasets`. The 
pipeline's semantic path (pipeline.py:113-122) is unreachable through this 
validator. Align the pre-check with the new view_id target. 
([CWE-20](https://cwe.mitre.org/data/definitions/20.html))
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #4e4a93</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