mikebridge commented on code in PR #44393:
URL: https://github.com/apache/superset/pull/44393#discussion_r4157275569


##########
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")

Review Comment:
   Good catch. The pinned test reproduced the failure, and 
`c2163e82c26d1b645c5fee2baad8c4c48e350e32` restores dataset 7's precedence 
across all three request models while still rejecting semantic family/ID 
conflicts. The pinned test and six new cases failed before the fix and pass 
after it. Could you take another look once the new CI run finishes?



##########
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:
   I traced this at `c2163e82c26d1b645c5fee2baad8c4c48e350e32` and the semantic 
target isn't blocked: `generate_chart` takes a separate semantic branch, and 
authorized semantic targets call `validate_semantic_view_config` directly. Only 
table requests enter `ValidationPipeline`, so its dataset requirement doesn't 
apply to them. The semantic tool tests pass without relaxing that validator.



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