You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/12/04 21:05:46 UTC

(superset) 01/15: fix: alias column when fetching values (#26120)

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

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

commit f4fd0e19e26a7545597da49cc9e1616fdc747433
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Nov 28 15:11:20 2023 -0500

    fix: alias column when fetching values (#26120)
    
    (cherry picked from commit 7223633da600fb3973834cb24d977f194a76f328)
---
 superset/models/helpers.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index fc947ff577..df3dd93488 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -1352,7 +1352,13 @@ class ExploreMixin:  # pylint: disable=too-many-public-methods
         tbl, cte = self.get_from_clause(tp)
 
         qry = (
-            sa.select([target_col.get_sqla_col(template_processor=tp)])
+            sa.select(
+                # The alias (label) here is important because some dialects will
+                # automatically add a random alias to the projection because of the
+                # call to DISTINCT; others will uppercase the column names. This
+                # gives us a deterministic column name in the dataframe.
+                [target_col.get_sqla_col(template_processor=tp).label("column_values")]
+            )
             .select_from(tbl)
             .distinct()
         )
@@ -1368,7 +1374,7 @@ class ExploreMixin:  # pylint: disable=too-many-public-methods
             sql = self.mutate_query_from_config(sql)
 
             df = pd.read_sql_query(sql=sql, con=engine)
-            return df[denormalized_col_name].to_list()
+            return df["column_values"].to_list()
 
     def get_timestamp_expression(
         self,