You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2026/06/24 22:42:07 UTC

(superset) branch claude/strange-banzai-d82afd created (now 8513f40563e)

This is an automated email from the ASF dual-hosted git repository.

sadpandajoe pushed a change to branch claude/strange-banzai-d82afd
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 8513f40563e fix(mixed-chart): preserve order_desc and series_limit_metric in buildQuery

This branch includes the following new commits:

     new 8513f40563e fix(mixed-chart): preserve order_desc and series_limit_metric in buildQuery

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(mixed-chart): preserve order_desc and series_limit_metric in buildQuery

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sadpandajoe pushed a commit to branch claude/strange-banzai-d82afd
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 8513f40563e2046ef31ff62529a1cdea1462dd02
Author: Joe Li <jo...@preset.io>
AuthorDate: Wed Jun 24 15:34:06 2026 -0700

    fix(mixed-chart): preserve order_desc and series_limit_metric in buildQuery
    
    MixedTimeseries buildQuery returned the full `normalizeOrderBy()` result,
    which deletes `order_desc` and `series_limit_metric` from its returned
    clone and re-adds only `orderby`. The backend main query reads `orderby`
    (so "View query" SQL updated correctly), but the series-limit subquery that
    selects which top-N series to display reads `order_desc` directly and the
    sort metric via `_get_series_orderby`. With both stripped, the backend
    QueryObject defaulted `order_desc` to True (descending), so toggling
    "Sort Descending" or changing "Sort Query By" never changed the rendered
    result.
    
    Spread the query object and overwrite only `orderby`, mirroring the
    single-query Timeseries chart's buildQuery. Adds a regression test that
    fails without the fix.
    
    Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
 .../src/MixedTimeseries/buildQuery.ts              | 13 +++++++-
 .../test/MixedTimeseries/buildQuery.test.ts        | 36 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts
index 625b932b19d..60673870e57 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts
@@ -82,7 +82,18 @@ export default function buildQuery(formData: QueryFormData) {
           flattenOperator(fd, queryObject),
         ],
       } as QueryObject;
-      return [normalizeOrderBy(tmpQueryObject)];
+      // Preserve `order_desc` and `series_limit_metric` on the query object and
+      // only normalize `orderby`. `normalizeOrderBy` strips those two fields from
+      // its result, but the backend series-limit subquery reads `order_desc`
+      // directly to pick the top-N series, so dropping it makes the sort
+      // direction silently ignored for the displayed result. Mirrors the
+      // single-query Timeseries chart's buildQuery.
+      return [
+        {
+          ...tmpQueryObject,
+          orderby: normalizeOrderBy(tmpQueryObject).orderby,
+        },
+      ];
     }),
   );
 
diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
index 7c265bb31e7..0f7226e58c9 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
@@ -106,7 +106,8 @@ test('should compile query object A', () => {
     row_offset: undefined,
     series_columns: ['foo'],
     series_limit: 5,
-    series_limit_metric: undefined,
+    series_limit_metric: 'count',
+    order_desc: true,
     group_others_when_limit_reached: false,
     url_params: {},
     custom_params: {},
@@ -167,6 +168,7 @@ test('should compile query object B', () => {
     series_columns: [],
     series_limit: 0,
     series_limit_metric: undefined,
+    order_desc: false,
     group_others_when_limit_reached: false,
     url_params: {},
     custom_params: {},
@@ -374,3 +376,35 @@ test('ensure correct pivot columns', () => {
     },
   });
 });
+
+test('preserves order_desc and series_limit_metric for both queries', () => {
+  // Regression for sc-107146: toggling "Sort Descending" off in a Mixed Chart
+  // updated the displayed SQL but not the rendered result. The backend
+  // series-limit subquery picks the top-N series from `order_desc`, so dropping
+  // it (as `normalizeOrderBy` does) made the sort direction silently ignored.
+  const ascendingFormData = {
+    ...formDataMixedChart,
+    order_desc: false,
+    order_desc_b: false,
+    timeseries_limit_metric_b: 'count',
+  };
+  const { queries } = buildQuery(ascendingFormData);
+
+  // Query A: ascending sort by its explicit sort metric must survive.
+  expect(queries[0]).toEqual(
+    expect.objectContaining({
+      order_desc: false,
+      series_limit_metric: 'count',
+      orderby: [['count', true]],
+    }),
+  );
+
+  // Query B: the `_b` query must independently keep its own direction/metric.
+  expect(queries[1]).toEqual(
+    expect.objectContaining({
+      order_desc: false,
+      series_limit_metric: 'count',
+      orderby: [['count', true]],
+    }),
+  );
+});