Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SQL label missing for non-group-by queries #29420

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
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
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
Loading