You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2024/07/01 08:59:31 UTC
(superset) branch master updated: fix: SQL label missing for non-group-by queries (#29420)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 179cf269c6 fix: SQL label missing for non-group-by queries (#29420)
179cf269c6 is described below
commit 179cf269c643c91a804eaf07ba3a66a8fcf65386
Author: Hex Café <15...@users.noreply.github.com>
AuthorDate: Mon Jul 1 16:59:25 2024 +0800
fix: SQL label missing for non-group-by queries (#29420)
---
superset/models/helpers.py | 4 +++-
tests/integration_tests/model_tests.py | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index 7b211f98b1..b841426ff7 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -1683,7 +1683,9 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
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(
diff --git a/tests/integration_tests/model_tests.py b/tests/integration_tests/model_tests.py
index 458168009b..fb22f40fb2 100644
--- a/tests/integration_tests/model_tests.py
+++ b/tests/integration_tests/model_tests.py
@@ -556,6 +556,29 @@ class TestSqlaTableModel(SupersetTestCase):
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")