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


##########
superset/mcp_service/chart/plugins/xy.py:
##########
@@ -103,6 +128,21 @@ def extract_column_refs(self, config: Any) -> 
list[ColumnRef]:
         if config.filters:
             for f in config.filters:
                 refs.append(ColumnRef(name=f.column))
+        if config.sort_by:
+            sort_entry = config.sort_by
+            if isinstance(sort_entry, list) and sort_entry:
+                sort_entry = sort_entry[0]
+            sort_col = (
+                sort_entry.column
+                if isinstance(sort_entry, SortByConfig)
+                else sort_entry
+                if isinstance(sort_entry, str)
+                else sort_entry.get("column")
+                if isinstance(sort_entry, dict)
+                else None
+            )
+            if sort_col:
+                refs.append(ColumnRef(name=sort_col))

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `a8ab8a7`.
   
   `sort_by` is now normalized through `_update_sort_by_column`, which resolves 
canonical names and marks saved metrics before downstream validation.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2350,6 +2350,38 @@ class XYChartConfig(BaseChartConfig):
         ge=1,
         le=10000,
     )
+    sort_by: SortByConfig | str | List[SortByConfig | str] | None = Field(
+        None,
+        description=(
+            "Sort specification for the chart. Accepts a SortByConfig object, "
+            "a bare column/metric name string (defaults to descending), or a "
+            "single-item list containing either."
+        ),
+        validation_alias=AliasChoices("sort_by", "x_axis_sort", "order_by"),
+    )
+
+    @field_validator("sort_by", mode="before")
+    @classmethod
+    def coerce_sort_by(cls, v: Any) -> Any:
+        """Coerce bare string, dict, or single-item list into SortByConfig."""
+        if v is None:
+            return None
+        if isinstance(v, str):
+            return SortByConfig(column=v, ascending=False)
+        if isinstance(v, list):
+            if not v:
+                return None
+            first = v[0]
+            if isinstance(first, str):
+                return SortByConfig(column=first, ascending=False)

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `a8ab8a7`.
   
   The validator now rejects lists with more than one sort entry by raising 
`ValueError`, preventing additional criteria from being silently discarded.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



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