Skip to content

Commit

Permalink
fix: SQL label missing for non-group-by queries (apache#29420)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexcafe authored Jul 1, 2024
1 parent ba405ba commit 179cf26
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 @@ -1683,7 +1683,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 @@ -556,6 +556,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 179cf26

Please sign in to comment.