Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,10 +1585,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
# use the existing instance.
col = metrics_exprs_by_expr.get(str(col), col)
need_groupby = True
elif col in columns_by_name:
col = self.convert_tbl_column_to_sqla_col(
columns_by_name[col], template_processor=template_processor
)
elif col in metrics_exprs_by_label:
col = metrics_exprs_by_label[col]
need_groupby = True
Expand All @@ -1597,6 +1593,10 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
template_processor=template_processor
)
need_groupby = True
elif col in columns_by_name:
col = self.convert_tbl_column_to_sqla_col(
columns_by_name[col], template_processor=template_processor
)
Comment on lines +1596 to +1599
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm basically just changing the order to first evaluate the column against metrics, and then across columns.

My understanding of the issue is that in the current if/elif ordering, we would first evaluate col across columns_by_name, which would be true (even tho it's a metric), and then convert_tbl_column_to_sqla_col() does col = sa.column(tbl_column.column_name, type_=type_) which seems to return quoted if the column is uppercase (hence the issue does not happen with normalize_columns disabled):

import sqlalchemy as sa
print(sa.column("test", sa.String))
print(sa.column("TEST", sa.String))
test
"TEST"

With normalize_columns, we send a lowercase column label to sa.column() which then does not quote it.


if isinstance(col, ColumnElement):
orderby_exprs.append(col)
Expand Down
Loading