From 435d5e7dd1455f6ac4a7ce90e8fbce2f2904ef9c Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 24 May 2017 23:07:26 -0700 Subject: [PATCH] Fix filter values populating for views --- superset/connectors/sqla/models.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index e3e8792e02d52..2afcc4d085caf 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -292,10 +292,9 @@ def values_for_column(self, column_name, limit=10000): cols = {col.column_name: col for col in self.columns} target_col = cols[column_name] - tbl = self.get_sqla_table() qry = ( select([target_col.sqla_col]) - .select_from(tbl) + .select_from(self.get_from_clause()) .distinct(column_name) ) if limit: @@ -338,6 +337,15 @@ def get_sqla_table(self): tbl.schema = self.schema return tbl + def get_from_clause(self): + # Supporting arbitrary SQL statements in place of tables + if self.sql: + tp = self.get_template_processor() + from_sql = tp.process_template(self.sql) + return TextAsFrom(sa.text(from_sql), []).alias('expr_qry') + + return self.get_sqla_table() + def get_sqla_query( # sqla self, groupby, metrics, @@ -436,12 +444,7 @@ def get_sqla_query( # sqla select_exprs += metrics_exprs qry = sa.select(select_exprs) - # Supporting arbitrary SQL statements in place of tables - if self.sql: - from_sql = template_processor.process_template(self.sql) - tbl = TextAsFrom(sa.text(from_sql), []).alias('expr_qry') - else: - tbl = self.get_sqla_table() + tbl = self.get_from_clause() if not columns: qry = qry.group_by(*groupby_exprs)