aminghadersohi commented on code in PR #44464:
URL: https://github.com/apache/superset/pull/44464#discussion_r4115242717
##########
superset/mcp_service/chart/chart_helpers.py:
##########
@@ -863,13 +898,19 @@ def build_query_dicts_from_form_data(
if x_axis_col and x_axis_col not in groupby:
groupby = [x_axis_col] + groupby
+ is_temporal = bool(
+ form_data.get("granularity_sqla")
+ or form_data.get("time_grain_sqla")
+ or viz_type == "mixed_timeseries"
+ )
Review Comment:
New Explore charts default `time_grain_sqla` to `P1D` whatever the x-axis
type, so this drops `x_axis_sort` for Explore-saved categorical bar charts; the
x-axis sort control already resets on temporal axes. No test covers this clause.
```suggestion
is_temporal = bool(
form_data.get("granularity_sqla") or viz_type == "mixed_timeseries"
)
```
##########
superset/mcp_service/chart/chart_helpers.py:
##########
@@ -699,8 +722,19 @@ def _build_single_query_dict(
# metric descending. buildQuery derives this on the frontend; translate
# the flag here when there is no explicit ordering or a row_limit truncates
# an unordered result (dropping the heaviest rows rather than the top-N).
+ viz_type = form_data.get("viz_type") or ""
+ is_temporal = (
+ is_timeseries
+ or viz_type == "mixed_timeseries"
+ or bool(form_data.get("granularity_sqla"))
+ )
if form_data.get("sort_by_metric") and metrics and not qd.get("orderby"):
qd["orderby"] = [(metrics[0], False)]
+ elif not is_temporal and form_data.get("x_axis_sort") and not
qd.get("orderby"):
+ sort_col = form_data["x_axis_sort"]
+ sort_asc = bool(form_data.get("x_axis_sort_asc", False))
+ sort_target = _resolve_x_axis_sort_target(sort_col, metrics)
+ qd["orderby"] = [(sort_target, sort_asc)]
Review Comment:
Still reproduces at this head when `time_grain_sqla` is unset: a saved
series-sort value (`sum`, `max`) becomes `orderby` and `get_chart_preview`
fails with `Unknown column used in orderby: sum`. Only order by a real metric
or column:
```suggestion
col_labels = [c if isinstance(c, str) else c.get("label") for c in
columns]
if sort_target in metrics or sort_target in col_labels:
qd["orderby"] = [(sort_target, sort_asc)]
```
--
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]