Skip to content

Commit 1e00f46

Browse files
committed
fix(warm_up_cache): JSON serialization
1 parent f036adb commit 1e00f46

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

superset/views/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
from superset.utils.cache import etag_cache
133133
from superset.utils.core import (
134134
apply_max_row_limit,
135+
base_json_conv,
135136
DatasourceType,
136137
get_user_id,
137138
ReservedUrlParameters,
@@ -1821,7 +1822,7 @@ def warm_up_cache( # pylint: disable=too-many-locals,no-self-use
18211822
{"slice_id": slc.id, "viz_error": error, "viz_status": status}
18221823
)
18231824

1824-
return json_success(json.dumps(result))
1825+
return json_success(json.dumps(result, default=base_json_conv))
18251826

18261827
@has_access_api
18271828
@event_logger.log_this

tests/integration_tests/core_tests.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343

4444
import pandas as pd
4545
import sqlalchemy as sqla
46+
from flask_babel import lazy_gettext as _
4647
from sqlalchemy.exc import SQLAlchemyError
48+
from superset.charts.commands.exceptions import ChartDataQueryFailedError
49+
from superset.charts.data.commands.get_data_command import ChartDataCommand
50+
from superset.exceptions import QueryObjectValidationError
4751
from superset.models.cache import CacheKey
4852
from superset.utils.database import get_example_database
4953
from tests.integration_tests.conftest import with_feature_flags
@@ -577,7 +581,8 @@ def test_databaseview_edit(self, username="admin"):
577581
db.session.commit()
578582

579583
@pytest.mark.usefixtures(
580-
"load_energy_table_with_slice", "load_birth_names_dashboard_with_slices"
584+
"load_birth_names_dashboard_with_slices",
585+
"load_energy_table_with_slice",
581586
)
582587
def test_warm_up_cache(self):
583588
self.login()
@@ -603,6 +608,26 @@ def test_warm_up_cache(self):
603608
+ quote(json.dumps([{"col": "name", "op": "in", "val": ["Jennifer"]}]))
604609
) == [{"slice_id": slc.id, "viz_error": None, "viz_status": "success"}]
605610

611+
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
612+
@mock.patch.object(ChartDataCommand, "run")
613+
def test_warm_up_cache_error(self, run_mock) -> None:
614+
self.login()
615+
slc = self.get_slice("Pivot Table v2", db.session)
616+
run_mock.side_effect = ChartDataQueryFailedError(
617+
_(
618+
"Error: %(error)s",
619+
error=_("Empty query?"),
620+
)
621+
)
622+
623+
assert self.get_json_resp(f"/superset/warm_up_cache?slice_id={slc.id}") == [
624+
{
625+
"slice_id": slc.id,
626+
"viz_error": "Error: Empty query?",
627+
"viz_status": None,
628+
}
629+
]
630+
606631
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
607632
def test_cache_logging(self):
608633
self.login("admin")

0 commit comments

Comments
 (0)