diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py index 773229ad5f753..152383e0c66d4 100644 --- a/superset/charts/data/api.py +++ b/superset/charts/data/api.py @@ -41,6 +41,7 @@ from superset.charts.schemas import ChartDataQueryContextSchema from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType from superset.connectors.base.models import BaseDatasource +from superset.dao.exceptions import DatasourceNotFound from superset.exceptions import QueryObjectValidationError from superset.extensions import event_logger from superset.utils.async_query_manager import AsyncQueryTokenException @@ -141,6 +142,8 @@ def get_data(self, pk: int) -> Response: query_context = self._create_query_context_from_form(json_body) command = ChartDataCommand(query_context) command.validate() + except DatasourceNotFound as error: + return self.response_404() except QueryObjectValidationError as error: return self.response_400(message=error.message) except ValidationError as error: @@ -229,6 +232,8 @@ def data(self) -> Response: query_context = self._create_query_context_from_form(json_body) command = ChartDataCommand(query_context) command.validate() + except DatasourceNotFound as error: + return self.response_404() except QueryObjectValidationError as error: return self.response_400(message=error.message) except ValidationError as error: