mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(cache): respect default cache timeout on v1 chart data requests (#21441)
This commit is contained in:
@@ -21,7 +21,7 @@ import unittest
|
||||
import copy
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
from typing import Optional
|
||||
from typing import Any, Dict, Optional
|
||||
from unittest import mock
|
||||
from zipfile import ZipFile
|
||||
|
||||
@@ -915,3 +915,64 @@ class TestGetChartDataApi(BaseTestChartDataApi):
|
||||
unique_genders = {row["male_or_female"] for row in data}
|
||||
assert unique_genders == {"male", "female"}
|
||||
assert result["applied_filters"] == [{"column": "male_or_female"}]
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def physical_query_context(physical_dataset) -> Dict[str, Any]:
|
||||
return {
|
||||
"datasource": {
|
||||
"type": physical_dataset.type,
|
||||
"id": physical_dataset.id,
|
||||
},
|
||||
"queries": [
|
||||
{
|
||||
"columns": ["col1"],
|
||||
"metrics": ["count"],
|
||||
"orderby": [["col1", True]],
|
||||
}
|
||||
],
|
||||
"result_type": ChartDataResultType.FULL,
|
||||
"force": True,
|
||||
}
|
||||
|
||||
|
||||
@mock.patch(
|
||||
"superset.common.query_context_processor.config",
|
||||
{
|
||||
**app.config,
|
||||
"CACHE_DEFAULT_TIMEOUT": 1234,
|
||||
"DATA_CACHE_CONFIG": {
|
||||
**app.config["DATA_CACHE_CONFIG"],
|
||||
"CACHE_DEFAULT_TIMEOUT": None,
|
||||
},
|
||||
},
|
||||
)
|
||||
def test_cache_default_timeout(test_client, login_as_admin, physical_query_context):
|
||||
rv = test_client.post(CHART_DATA_URI, json=physical_query_context)
|
||||
assert rv.json["result"][0]["cache_timeout"] == 1234
|
||||
|
||||
|
||||
def test_custom_cache_timeout(test_client, login_as_admin, physical_query_context):
|
||||
physical_query_context["custom_cache_timeout"] = 5678
|
||||
rv = test_client.post(CHART_DATA_URI, json=physical_query_context)
|
||||
assert rv.json["result"][0]["cache_timeout"] == 5678
|
||||
|
||||
|
||||
@mock.patch(
|
||||
"superset.common.query_context_processor.config",
|
||||
{
|
||||
**app.config,
|
||||
"CACHE_DEFAULT_TIMEOUT": 100000,
|
||||
"DATA_CACHE_CONFIG": {
|
||||
**app.config["DATA_CACHE_CONFIG"],
|
||||
"CACHE_DEFAULT_TIMEOUT": 3456,
|
||||
},
|
||||
},
|
||||
)
|
||||
def test_data_cache_default_timeout(
|
||||
test_client,
|
||||
login_as_admin,
|
||||
physical_query_context,
|
||||
):
|
||||
rv = test_client.post(CHART_DATA_URI, json=physical_query_context)
|
||||
assert rv.json["result"][0]["cache_timeout"] == 3456
|
||||
|
||||
Reference in New Issue
Block a user