From 244372d679ef5edd3a3e61c18d2c9b7c78d088d6 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 12 Sep 2022 15:08:59 -0700 Subject: [PATCH 1/4] duck typing --- superset/models/helpers.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/superset/models/helpers.py b/superset/models/helpers.py index c81d268a1eec2..f566c44987f57 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -1570,26 +1570,24 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma groupby_all_columns[timestamp.name] = timestamp # Use main dttm column to support index with secondary dttm columns. - if ( - db_engine_spec.time_secondary_columns - and self.main_dttm_col in self.dttm_cols - and self.main_dttm_col != dttm_col.column_name - ): - if isinstance(self.main_dttm_col, dict): - time_filters.append( - self.get_time_filter( - self.main_dttm_col, - from_dttm, - to_dttm, + if db_engine_spec.time_secondary_columns: + dttm_col_name = dttm_col.get('column_name') if isinstance(dttm_col, dict) else dttm_col.column_name + if self.main_dttm_col in self.dttm_cols and self.main_dttm_col != dttm_col_name: + if isinstance(self.main_dttm_col, dict): + time_filters.append( + self.get_time_filter( + self.main_dttm_col, + from_dttm, + to_dttm, + ) ) - ) - else: - time_filters.append( - columns_by_name[self.main_dttm_col].get_time_filter( - from_dttm, - to_dttm, + else: + time_filters.append( + columns_by_name[self.main_dttm_col].get_time_filter( + from_dttm, + to_dttm, + ) ) - ) if isinstance(dttm_col, dict): time_filters.append(self.get_time_filter(dttm_col, from_dttm, to_dttm)) From a44caf03f3d7879b15415cbb42ac47794f56997f Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 12 Sep 2022 15:40:30 -0700 Subject: [PATCH 2/4] refactor --- superset/models/helpers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/superset/models/helpers.py b/superset/models/helpers.py index f566c44987f57..893f1abd0bf01 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -1571,7 +1571,11 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma # Use main dttm column to support index with secondary dttm columns. if db_engine_spec.time_secondary_columns: - dttm_col_name = dttm_col.get('column_name') if isinstance(dttm_col, dict) else dttm_col.column_name + if isinstance(dttm_col, dict): + dttm_col_name = dttm_col.get('column_name') + else: + dttm_col_name = dttm_col.column_name + if self.main_dttm_col in self.dttm_cols and self.main_dttm_col != dttm_col_name: if isinstance(self.main_dttm_col, dict): time_filters.append( From 8b747960b39017c3eb90418dccae65a99aefe4c1 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 26 Sep 2022 12:57:26 -0400 Subject: [PATCH 3/4] fix linting --- superset/models/helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/superset/models/helpers.py b/superset/models/helpers.py index 893f1abd0bf01..3453cdbefaf12 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -1576,7 +1576,10 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma else: dttm_col_name = dttm_col.column_name - if self.main_dttm_col in self.dttm_cols and self.main_dttm_col != dttm_col_name: + if ( + self.main_dttm_col in self.dttm_cols and + self.main_dttm_col != dttm_col_name + ): if isinstance(self.main_dttm_col, dict): time_filters.append( self.get_time_filter( From 40fe3136f2bac24c21d7d1ddf1e3e9b9a9b10b2d Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 26 Sep 2022 15:23:55 -0400 Subject: [PATCH 4/4] fix --- superset/models/helpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset/models/helpers.py b/superset/models/helpers.py index 3453cdbefaf12..da526b559c7f1 100644 --- a/superset/models/helpers.py +++ b/superset/models/helpers.py @@ -1572,13 +1572,13 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma # Use main dttm column to support index with secondary dttm columns. if db_engine_spec.time_secondary_columns: if isinstance(dttm_col, dict): - dttm_col_name = dttm_col.get('column_name') + dttm_col_name = dttm_col.get("column_name") else: dttm_col_name = dttm_col.column_name if ( - self.main_dttm_col in self.dttm_cols and - self.main_dttm_col != dttm_col_name + self.main_dttm_col in self.dttm_cols + and self.main_dttm_col != dttm_col_name ): if isinstance(self.main_dttm_col, dict): time_filters.append(