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

chore(chart-data): add post processing error message to response #23734

Merged
merged 2 commits into from
Apr 19, 2023
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
2 changes: 1 addition & 1 deletion superset/common/query_context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def get_query_result(self, query_object: QueryObject) -> QueryResult:
try:
df = query_object.exec_post_processing(df)
except InvalidPostProcessingError as ex:
raise QueryObjectValidationError from ex
raise QueryObjectValidationError(ex.message) from ex

result.df = df
result.query = query
Expand Down
27 changes: 27 additions & 0 deletions tests/integration_tests/charts/data/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,33 @@ def test_chart_data_prophet(self):
self.assertIn("sum__num__yhat_lower", row)
self.assertEqual(result["rowcount"], 47)

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_chart_data_invalid_post_processing(self):
"""
Chart data API: Ensure incorrect post processing returns correct response
"""
query_context = self.query_context_payload
query = query_context["queries"][0]
query["columns"] = ["name", "gender"]
query["post_processing"] = [
{
"operation": "pivot",
"options": {
"drop_missing_columns": False,
"columns": ["gender"],
"index": ["name"],
"aggregates": {},
},
},
]
rv = self.post_assert_metric(CHART_DATA_URI, query_context, "data")
assert rv.status_code == 400
data = json.loads(rv.data.decode("utf-8"))
assert (
data["message"]
== "Error: Pivot operation must include at least one aggregate"
)

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_with_query_result_type_and_non_existent_filter__filter_omitted(self):
self.query_context_payload["queries"][0]["filters"] = [
Expand Down