Skip to content

Commit

Permalink
fix: SQL label missing for non-group-by queries (#29420)
Browse files Browse the repository at this point in the history
(cherry picked from commit 179cf26)
  • Loading branch information
hexcafe authored and michael-s-molina committed Aug 13, 2024
1 parent e5acbd9 commit 9b547ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,9 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma

select_exprs.append(
self.convert_tbl_column_to_sqla_col(
columns_by_name[selected], template_processor=template_processor
columns_by_name[selected],
template_processor=template_processor,
label=_column_label,
)
if isinstance(selected, str) and selected in columns_by_name
else self.make_sqla_column_compatible(
Expand Down
23 changes: 23 additions & 0 deletions tests/integration_tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,29 @@ def test_query_with_non_existent_metrics(self):

self.assertTrue("Metric 'invalid' does not exist", context.exception)

def test_query_label_without_group_by(self):
tbl = self.get_table(name="birth_names")
query_obj = dict(
groupby=[],
columns=[
"gender",
{
"label": "Given Name",
"sqlExpression": "name",
"expressionType": "SQL",
},
],
filter=[],
is_timeseries=False,
granularity=None,
from_dttm=None,
to_dttm=None,
extras={},
)

sql = tbl.get_query_str(query_obj)
self.assertRegex(sql, r'name AS ["`]?Given Name["`]?')

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_data_for_slices_with_no_query_context(self):
tbl = self.get_table(name="birth_names")
Expand Down

0 comments on commit 9b547ed

Please sign in to comment.