4343
4444import pandas as pd
4545import sqlalchemy as sqla
46+ from flask_babel import lazy_gettext as _
4647from 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
4751from superset .models .cache import CacheKey
4852from superset .utils .database import get_example_database
4953from 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