Skip to content

Commit

Permalink
fix(chart-filter): Avoid column denormalization if not enabled (#26199)
Browse files Browse the repository at this point in the history
(cherry picked from commit 05d7060)
  • Loading branch information
Vitor-Avila authored and michael-s-molina committed Dec 8, 2023
1 parent 52f12ba commit 8eb6bbb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion superset/datasource/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ def get_column_values(
return self.response(403, message=ex.message)

row_limit = apply_max_row_limit(app.config["FILTER_SELECT_ROW_LIMIT"])
denormalize_column = not datasource.normalize_columns
try:
payload = datasource.values_for_column(
column_name=column_name, limit=row_limit
column_name=column_name,
limit=row_limit,
denormalize_column=denormalize_column,
)
return self.response(200, result=payload)
except KeyError:
Expand Down
15 changes: 10 additions & 5 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,14 +1331,19 @@ def get_time_filter( # pylint: disable=too-many-arguments
)
return and_(*l)

def values_for_column(self, column_name: str, limit: int = 10000) -> list[Any]:
# always denormalize column name before querying for values
def values_for_column(
self, column_name: str, limit: int = 10000, denormalize_column: bool = False
) -> list[Any]:
# denormalize column name before querying for values
# unless disabled in the dataset configuration
db_dialect = self.database.get_dialect()
denormalized_col_name = self.database.db_engine_spec.denormalize_name(
db_dialect, column_name
column_name_ = (
self.database.db_engine_spec.denormalize_name(db_dialect, column_name)
if denormalize_column
else column_name
)
cols = {col.column_name: col for col in self.columns}
target_col = cols[denormalized_col_name]
target_col = cols[column_name_]
tp = self.get_template_processor()
tbl, cte = self.get_from_clause(tp)

Expand Down

0 comments on commit 8eb6bbb

Please sign in to comment.