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


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -1045,6 +1045,63 @@ def reject_sql_expression_on_dimensions(self) -> 
"PieChartConfig":
         return self
 
 
+class SankeyChartConfig(BaseChartConfig):
+    """Config for sankey charts (viz_type ``sankey_v2``).
+
+    Matches the frontend Sankey buildQuery contract: a ``source`` and a
+    ``target`` column define the edges of the flow diagram and one ``metric``
+    weights each edge. When ``sort_by_metric`` is set the query orders by the
+    metric descending.
+    """
+
+    model_config = ConfigDict(extra="ignore", populate_by_name=True)
+
+    chart_type: Literal["sankey_v2"] = "sankey_v2"
+    source: ColumnRef = Field(
+        ...,
+        description="Column used as the source (origin) node of each edge",
+    )
+    target: ColumnRef = Field(
+        ...,
+        description="Column used as the target (destination) node of each 
edge",
+    )
+    metric: ColumnRef = Field(
+        ...,
+        description="Metric weighting each edge (use aggregate e.g. SUM, "
+        "COUNT for ad-hoc, or set saved_metric=True for a saved dataset 
metric)",
+    )
+    sort_by_metric: bool = Field(
+        True,
+        description="Order edges by the metric descending (frontend default)",
+    )
+    row_limit: int = Field(10000, description="Max edges queried", ge=1, 
le=100000)
+    filters: List[FilterConfig] | None = Field(
+        None,
+        description="Structured filters (column/op/value). "
+        "Do NOT use adhoc_filters or raw SQL expressions.",
+    )
+    color_scheme: str | None = Field(
+        None,
+        description=(
+            "Superset color scheme ID (e.g. 'supersetColors', 'lyftColors', "
+            "'googleCategory10c', 'd3Category10'). Defaults to 
'supersetColors'."
+        ),
+        max_length=100,
+    )
+
+    @model_validator(mode="after")
+    def reject_metric_style_nodes(self) -> "SankeyChartConfig":
+        """source and target are node dimensions, not metrics."""
+        for col, name in ((self.source, "source"), (self.target, "target")):
+            _reject_sql_expression_on_dimension(col, name)
+            if col and col.saved_metric:
+                raise ValueError(
+                    f"{name} cannot use saved_metric=True; "
+                    "saved metrics belong in the 'metric' field"
+                )

Review Comment:
   **Suggestion:** Dimension validation rejects `sql_expression` and 
`saved_metric`, but it does not reject `aggregate` on `source` or `target`. 
Such a configuration passes schema and dataset aggregation validation for 
compatible aggregates, then `map_sankey_config` discards the aggregate and 
emits only the raw column name, silently changing the requested Sankey 
semantics. Reject aggregated source/target references during validation. [type 
error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Sankey charts can show flows grouped by raw nodes despite requested 
source/target aggregation.
   - ⚠️ `generate_chart` accepts invalid dimension configuration without 
feedback.
   - ⚠️ Saved charts preserve misleading configuration semantics in generated 
form data.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7c7ba0f482d74d56845c307d6bc0984f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7c7ba0f482d74d56845c307d6bc0984f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/chart/schemas.py
   **Line:** 1095:1101
   **Comment:**
        *Type Error: Dimension validation rejects `sql_expression` and 
`saved_metric`, but it does not reject `aggregate` on `source` or `target`. 
Such a configuration passes schema and dataset aggregation validation for 
compatible aggregates, then `map_sankey_config` discards the aggregate and 
emits only the raw column name, silently changing the requested Sankey 
semantics. Reject aggregated source/target references during validation.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43573&comment_hash=31f06ffe57b8507f719dd383d2f2c07be96e344a76975468ca5744e2abbc43ff&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43573&comment_hash=31f06ffe57b8507f719dd383d2f2c07be96e344a76975468ca5744e2abbc43ff&reaction=dislike'>👎</a>



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