fix(mixed-chart): preserve order_desc and series_limit_metric in buildQuery#41401
fix(mixed-chart): preserve order_desc and series_limit_metric in buildQuery#41401sadpandajoe wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41401 +/- ##
==========================================
- Coverage 64.37% 64.37% -0.01%
==========================================
Files 2653 2653
Lines 145152 145152
Branches 33491 33491
==========================================
- Hits 93446 93440 -6
- Misses 50014 50020 +6
Partials 1692 1692
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…dQuery 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 <noreply@anthropic.com>
8513f40 to
2576241
Compare
There was a problem hiding this comment.
Pull request overview
Fixes Mixed Timeseries (mixed_timeseries) query construction so changing “Sort Query By” and “Sort Descending” affects not only the displayed SQL but also the rendered top‑N series selection. The frontend now preserves order_desc and series_limit_metric while still normalizing orderby, matching the established pattern used by the single-query Timeseries chart.
Changes:
- Update MixedTimeseries
buildQueryto spread the original query object and override onlyorderbyusingnormalizeOrderBy(...). - Adjust existing unit tests to assert
order_desc/series_limit_metricare preserved on compiled query objects. - Add a regression test covering the “Sort Descending off” repro for both Query A and Query B.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts | Preserve order_desc and series_limit_metric while normalizing orderby so series-limit behavior matches user sort controls. |
| superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts | Update expectations and add regression coverage ensuring both Mixed queries keep order_desc/series_limit_metric. |
SUMMARY
In a Mixed Chart (
mixed_timeseries), changing "Sort Query By" or toggling "Sort Descending" updated the displayed SQL ("View query") but did not change the rendered result.Root cause is in the frontend query builder.
MixedTimeseries/buildQuery.tsreturned the full output ofnormalizeOrderBy(tmpQueryObject).normalizeOrderBydeletesorder_descandseries_limit_metricfrom the object it returns, re-adding onlyorderby. The backend main query readsorderby(so the displayed SQL looks correct), but the series-limit subquery that decides which top-N series to show readsorder_descandseries_limit_metricdirectly (superset/models/helpers.py:direction = sa.desc if order_desc else sa.asc, and_get_series_orderbyreadsseries_limit_metric). With those two fields stripped, the backendQueryObjectdefaultsorder_desctoTrue, so the same top-N series were always selected → the result never changed.The fix mirrors what the single-query Timeseries chart already does: spread the query object and override only
orderby, preservingorder_descandseries_limit_metric.This applies symmetrically to Query A and Query B.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — no visual chrome change. The behavior change is that the rendered series now respond to the sort controls (see Testing Instructions).
TESTING INSTRUCTIONS
Automated coverage (
plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts):order_descandseries_limit_metricare preserved.preserves order_desc and series_limit_metric for both queries, asserting the sc-107146 ascending-sort repro keepsorder_desc: false+series_limit_metricfor both queries. Reverting only the source fix fails this test.Run:
npm run test -- plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.tsADDITIONAL INFORMATION
Reviewer / QA note — expected behavior change on existing saved charts
Preserving
series_limit_metricchanges the series-limit subquery's ORDER BY column, not just its direction. Previously the field was stripped, so the backend fell back to ordering the top-N prequery by the main metric; with the fix it orders by the chosen "Sort Query By" metric (helpers.py_get_series_orderby). This is the intended correctness fix, but existing saved Mixed Charts may render a different (correct) top-N series set with no user action. Please don't mistake this for a regression during QA.