Skip to content

Commit

Permalink
[fix] warm up cache error handling (#9560)
Browse files Browse the repository at this point in the history
Co-authored-by: John Bodley <john.bodley@airbnb.com>
  • Loading branch information
john-bodley and john-bodley committed Apr 16, 2020
1 parent 7b11b44 commit 074e365
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions superset/views/core.py
Expand Up @@ -1694,6 +1694,8 @@ def warm_up_cache(self):
.all()
)

result = []

for slc in slices:
try:
form_data = get_form_data(slc.id, use_slice_data=True)[0]
Expand All @@ -1707,15 +1709,18 @@ def warm_up_cache(self):
form_data=form_data,
force=True,
)
obj.get_json()
payload = obj.get_payload()
error = payload["error"]
status = payload["status"]
except Exception as ex:
logger.exception("Failed to warm up cache")
return json_error_response(utils.error_msg_from_exception(ex))
return json_success(
json.dumps(
[{"slice_id": slc.id, "slice_name": slc.slice_name} for slc in slices]
error = utils.error_msg_from_exception(ex)
status = None

result.append(
{"slice_id": slc.id, "viz_error": error, "viz_status": status}
)
)

return json_success(json.dumps(result))

@has_access_api
@expose("/favstar/<class_name>/<obj_id>/<action>/")
Expand Down
4 changes: 3 additions & 1 deletion tests/core_tests.py
Expand Up @@ -610,7 +610,9 @@ def test_databaseview_edit(self, username="admin"):
def test_warm_up_cache(self):
slc = self.get_slice("Girls", db.session)
data = self.get_json_resp("/superset/warm_up_cache?slice_id={}".format(slc.id))
self.assertEqual(data, [{"slice_id": slc.id, "slice_name": slc.slice_name}])
self.assertEqual(
data, [{"slice_id": slc.id, "viz_error": None, "viz_status": "success"}]
)

data = self.get_json_resp(
"/superset/warm_up_cache?table_name=energy_usage&db_name=main"
Expand Down

0 comments on commit 074e365

Please sign in to comment.