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(reports): force data generation in csv reports #22196

Merged
merged 7 commits into from
Nov 26, 2022
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
6 changes: 6 additions & 0 deletions superset/charts/data/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def get_data(self, pk: int) -> Response:
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
Expand Down Expand Up @@ -130,6 +135,7 @@ def get_data(self, pk: int) -> Response:
"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)
Expand Down
1 change: 1 addition & 0 deletions superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,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)
Expand Down
50 changes: 50 additions & 0 deletions tests/integration_tests/charts/data/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,56 @@ def test_chart_data_get(self):
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")
Expand Down