You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2026/04/15 18:21:02 UTC

(superset) branch master updated: fix(table): use column label instead of SQL expression for orderby in downloads (#39332)

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

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b3e88db87e4 fix(table): use column label instead of SQL expression for orderby in downloads (#39332)
b3e88db87e4 is described below

commit b3e88db87e486526af2ac6363bece3e4c3ed2985
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Wed Apr 15 11:20:54 2026 -0700

    fix(table): use column label instead of SQL expression for orderby in downloads (#39332)
    
    Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
 .../plugin-chart-ag-grid-table/src/buildQuery.ts    | 11 +++++------
 .../test/buildQuery.test.ts                         | 21 ++++++++++++++++++++-
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts
index 3d04b6c1d1c..bbee0e3ab0b 100644
--- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts
+++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts
@@ -238,12 +238,11 @@ const buildQuery: BuildQuery<TableChartFormData> = (
         });
 
         if (matchingColumn) {
-          if (
-            typeof matchingColumn === 'object' &&
-            'sqlExpression' in matchingColumn
-          ) {
-            return matchingColumn.sqlExpression;
-          }
+          // Return the label, not the raw sqlExpression. The backend
+          // (helpers.py get_sqla_query) resolves orderby strings by
+          // matching adhoc column labels, then uses adhoc_column_to_sqla
+          // to emit the actual SQL expression into ORDER BY — so this
+          // is dialect-safe across all database engines.
           return getColumnLabel(matchingColumn);
         }
 
diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/test/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-ag-grid-table/test/buildQuery.test.ts
index acec22c6965..ecb00812330 100644
--- a/superset-frontend/plugins/plugin-chart-ag-grid-table/test/buildQuery.test.ts
+++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/test/buildQuery.test.ts
@@ -90,7 +90,7 @@ describe('plugin-chart-ag-grid-table', () => {
         },
       ).queries[0];
 
-      expect(query.orderby).toEqual([['degree_type', true]]);
+      expect(query.orderby).toEqual([['Highest Degree', true]]);
     });
 
     test('should map string metric colId to backend identifier', () => {
@@ -267,6 +267,25 @@ describe('plugin-chart-ag-grid-table', () => {
       ]);
     });
 
+    test('should use label (not sqlExpression) for adhoc column in CSV export sortModel', () => {
+      const adhocColumn = createAdhocColumn('sales / 100', 'Margin');
+
+      const query = buildQuery(
+        {
+          ...basicFormData,
+          groupby: [adhocColumn],
+          result_format: 'csv',
+        },
+        {
+          ownState: {
+            sortModel: [{ colId: 'Margin', sort: 'desc' }],
+          },
+        },
+      ).queries[0];
+
+      expect(query.orderby?.[0]).toEqual(['Margin', false]);
+    });
+
     test('should not add tie-breaker for non-download queries with server pagination', () => {
       const query = buildQuery(
         {