mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(dashboard): Charts crashing when cross filter on adhoc column is applied (#23238)
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
006f3dd88c
commit
42980a69a7
@@ -56,6 +56,7 @@ from superset.utils.core import (
|
||||
AnnotationType,
|
||||
get_example_default_schema,
|
||||
AdhocMetricExpressionType,
|
||||
ExtraFiltersReasonType,
|
||||
)
|
||||
from superset.utils.database import get_example_database, get_main_database
|
||||
from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType
|
||||
@@ -73,6 +74,12 @@ ADHOC_COLUMN_FIXTURE: AdhocColumn = {
|
||||
"when gender = 'girl' then 'female' else 'other' end",
|
||||
}
|
||||
|
||||
INCOMPATIBLE_ADHOC_COLUMN_FIXTURE: AdhocColumn = {
|
||||
"hasCustomLabel": True,
|
||||
"label": "exciting_or_boring",
|
||||
"sqlExpression": "case when genre = 'Action' then 'Exciting' else 'Boring' end",
|
||||
}
|
||||
|
||||
|
||||
class BaseTestChartDataApi(SupersetTestCase):
|
||||
query_context_payload_template = None
|
||||
@@ -1059,6 +1066,33 @@ class TestGetChartDataApi(BaseTestChartDataApi):
|
||||
assert unique_genders == {"male", "female"}
|
||||
assert result["applied_filters"] == [{"column": "male_or_female"}]
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_chart_data_with_incompatible_adhoc_column(self):
|
||||
"""
|
||||
Chart data API: Test query with adhoc column that fails to run on this dataset
|
||||
"""
|
||||
self.login(username="admin")
|
||||
request_payload = get_query_context("birth_names")
|
||||
request_payload["queries"][0]["columns"] = [ADHOC_COLUMN_FIXTURE]
|
||||
request_payload["queries"][0]["filters"] = [
|
||||
{"col": INCOMPATIBLE_ADHOC_COLUMN_FIXTURE, "op": "IN", "val": ["Exciting"]},
|
||||
{"col": ADHOC_COLUMN_FIXTURE, "op": "IN", "val": ["male", "female"]},
|
||||
]
|
||||
rv = self.post_assert_metric(CHART_DATA_URI, request_payload, "data")
|
||||
response_payload = json.loads(rv.data.decode("utf-8"))
|
||||
result = response_payload["result"][0]
|
||||
data = result["data"]
|
||||
assert {column for column in data[0].keys()} == {"male_or_female", "sum__num"}
|
||||
unique_genders = {row["male_or_female"] for row in data}
|
||||
assert unique_genders == {"male", "female"}
|
||||
assert result["applied_filters"] == [{"column": "male_or_female"}]
|
||||
assert result["rejected_filters"] == [
|
||||
{
|
||||
"column": "exciting_or_boring",
|
||||
"reason": ExtraFiltersReasonType.COL_NOT_IN_DATASOURCE,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def physical_query_context(physical_dataset) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user