This is an automated email from the ASF dual-hosted git repository.
yongjiezhao 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 a8bc53d805 fix(reports): force data generation in csv reports (#22196)
a8bc53d805 is described below
commit a8bc53d805b404adf395cf7a844402fffd6fe220
Author: Mayur <[email protected]>
AuthorDate: Sat Nov 26 11:00:26 2022 +0530
fix(reports): force data generation in csv reports (#22196)
---
superset/charts/data/api.py | 6 +++
superset/charts/schemas.py | 1 +
tests/integration_tests/charts/data/api_tests.py | 50 ++++++++++++++++++++++++
3 files changed, 57 insertions(+)
diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py
index c20fdde6fd..773229ad5f 100644
--- a/superset/charts/data/api.py
+++ b/superset/charts/data/api.py
@@ -89,6 +89,11 @@ class ChartDataRestApi(ChartRestApi):
description: The type in which the data should be returned
schema:
type: string
+ - in: query
+ name: force
+ description: Should the queries be forced to load from the source
+ schema:
+ type: boolean
responses:
200:
description: Query result
@@ -130,6 +135,7 @@ class ChartDataRestApi(ChartRestApi):
"format", ChartDataResultFormat.JSON
)
json_body["result_type"] = request.args.get("type",
ChartDataResultType.FULL)
+ json_body["force"] = request.args.get("force")
try:
query_context = self._create_query_context_from_form(json_body)
diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py
index 6033e09035..dee73de17c 100644
--- a/superset/charts/schemas.py
+++ b/superset/charts/schemas.py
@@ -1205,6 +1205,7 @@ class ChartDataQueryContextSchema(Schema):
force = fields.Boolean(
description="Should the queries be forced to load from the source. "
"Default: `false`",
+ allow_none=True,
)
result_type = EnumField(ChartDataResultType, by_value=True)
diff --git a/tests/integration_tests/charts/data/api_tests.py
b/tests/integration_tests/charts/data/api_tests.py
index 8b2fd99388..d83cb8286b 100644
--- a/tests/integration_tests/charts/data/api_tests.py
+++ b/tests/integration_tests/charts/data/api_tests.py
@@ -862,6 +862,56 @@ class TestGetChartDataApi(BaseTestChartDataApi):
assert data["result"][0]["status"] == "success"
assert data["result"][0]["rowcount"] == 2
+ @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
+ def test_chart_data_get_forced(self):
+ """
+ Chart data API: Test GET endpoint with force cache parameter
+ """
+ chart = db.session.query(Slice).filter_by(slice_name="Genders").one()
+ chart.query_context = json.dumps(
+ {
+ "datasource": {"id": chart.table.id, "type": "table"},
+ "force": False,
+ "queries": [
+ {
+ "time_range": "1900-01-01T00:00:00 :
2000-01-01T00:00:00",
+ "granularity": "ds",
+ "filters": [],
+ "extras": {
+ "having": "",
+ "having_druid": [],
+ "where": "",
+ },
+ "applied_time_extras": {},
+ "columns": ["gender"],
+ "metrics": ["sum__num"],
+ "orderby": [["sum__num", False]],
+ "annotation_layers": [],
+ "row_limit": 50000,
+ "timeseries_limit": 0,
+ "order_desc": True,
+ "url_params": {},
+ "custom_params": {},
+ "custom_form_data": {},
+ }
+ ],
+ "result_format": "json",
+ "result_type": "full",
+ }
+ )
+
+ self.get_assert_metric(f"api/v1/chart/{chart.id}/data/?force=true",
"get_data")
+
+ # should burst cache
+ rv = self.get_assert_metric(
+ f"api/v1/chart/{chart.id}/data/?force=true", "get_data"
+ )
+ assert rv.json["result"][0]["is_cached"] is None
+
+ # should get response from the cache
+ rv = self.get_assert_metric(f"api/v1/chart/{chart.id}/data/",
"get_data")
+ assert rv.json["result"][0]["is_cached"]
+
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@with_feature_flags(GLOBAL_ASYNC_QUERIES=True)
@mock.patch("superset.charts.data.api.QueryContextCacheLoader")