forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(charts): Fix chart load task error handling (apache#24447)
- Loading branch information
Showing
4 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from flask_babel import lazy_gettext as _ | ||
|
||
from superset.charts.commands.exceptions import ChartDataQueryFailedError | ||
|
||
|
||
@mock.patch("superset.tasks.async_queries.security_manager") | ||
@mock.patch("superset.tasks.async_queries.async_query_manager") | ||
@mock.patch("superset.tasks.async_queries.ChartDataQueryContextSchema") | ||
def test_load_chart_data_into_cache_with_error( | ||
mock_query_context_schema_cls, mock_async_query_manager, mock_security_manager | ||
): | ||
"""Test that the task is gracefully marked failed in event of error""" | ||
from superset.tasks.async_queries import load_chart_data_into_cache | ||
|
||
job_metadata = {"user_id": 1} | ||
form_data = {} | ||
err_message = "Something went wrong" | ||
err = ChartDataQueryFailedError(_(err_message)) | ||
|
||
mock_user = mock.MagicMock() | ||
mock_query_context_schema = mock.MagicMock() | ||
|
||
mock_security_manager.get_user_by_id.return_value = mock_user | ||
mock_async_query_manager.STATUS_ERROR = "error" | ||
mock_query_context_schema_cls.return_value = mock_query_context_schema | ||
|
||
mock_query_context_schema.load.side_effect = err | ||
|
||
with pytest.raises(ChartDataQueryFailedError): | ||
load_chart_data_into_cache(job_metadata, form_data) | ||
|
||
expected_errors = [{"message": err_message}] | ||
|
||
mock_async_query_manager.update_job.assert_called_once_with( | ||
job_metadata, "error", errors=expected_errors | ||
) |