aminghadersohi commented on code in PR #42841:
URL: https://github.com/apache/superset/pull/42841#discussion_r3734024605


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -900,6 +900,41 @@ class AxisConfig(UnknownFieldCheckMixin):
     format: str | None = Field(None, description="e.g. '$,.2f'", max_length=50)
 
 
+def _route_x_axis_key(data: Any, column_keys: tuple[str, ...]) -> Any:
+    """Route an ``x_axis`` payload to the column field or to axis styling.
+
+    Native ``form_data`` names the x-axis column ``x_axis``, and models that
+    accept it as a column alias also expose an ``x_axis`` styling field, so a
+    single input key would otherwise feed both. The payload's shape decides:
+    a bare string, or a non-empty mapping that names no styling field, is a
+    column reference and is moved to ``x``; anything else stays put and
+    configures the axis. Keying off the styling names rather than the column
+    names keeps a mistyped styling key ("sort_by") reported against
+    ``AxisConfig``, where the caller meant it, instead of against 
``ColumnRef``.
+    """
+    if not isinstance(data, dict) or "x_axis" not in data:
+        return data
+    value = data["x_axis"]
+    is_column_ref = isinstance(value, str) or (
+        isinstance(value, dict)
+        and bool(value)
+        and not set(value) & set(AxisConfig.model_fields)

Review Comment:
   Non-blocking heuristic edge: the column-vs-styling split keys off whether 
the dict names any `AxisConfig` field (`{title, scale, format}`). A styling 
payload whose keys are *all* mistyped — e.g. `{"titel": "State"}` — intersects 
none of them, so it routes to `x` and surfaces as `Unknown field 'titel'` 
against the *column*, the opposite of the routing goal documented in the 
docstring. A partially-mistyped styling dict (`{"title", "sort_by"}`) is 
anchored correctly and is tested; the all-keys-wrong case isn't. Low impact 
since such a payload is unusable either way — just flagging the heuristic's 
boundary.
   



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