You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "diegomedina248 (via GitHub)" <gi...@apache.org> on 2023/01/24 17:25:20 UTC

[GitHub] [superset] diegomedina248 commented on a diff in pull request #22809: chore: migrate /sql_json and /results to apiv1

diegomedina248 commented on code in PR #22809:
URL: https://github.com/apache/superset/pull/22809#discussion_r1085654647


##########
superset/sqllab/api.py:
##########
@@ -0,0 +1,250 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import logging
+from typing import Any, cast, Dict, Optional
+
+from flask import request, Response
+from flask_appbuilder.api import expose, protect, rison, safe
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+from marshmallow import ValidationError
+
+from superset import app, is_feature_enabled
+from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP
+from superset.databases.dao import DatabaseDAO
+from superset.extensions import event_logger
+from superset.jinja_context import get_template_processor
+from superset.models.sql_lab import Query
+from superset.queries.dao import QueryDAO
+from superset.sql_lab import get_sql_results
+from superset.sqllab.command_status import SqlJsonExecutionStatus
+from superset.sqllab.commands.execute import CommandResult, ExecuteSqlCommand
+from superset.sqllab.commands.results import SqlExecutionResultsCommand
+from superset.sqllab.exceptions import (
+    QueryIsForbiddenToAccessException,
+    SqlLabException,
+)
+from superset.sqllab.execution_context_convertor import ExecutionContextConvertor
+from superset.sqllab.query_render import SqlQueryRenderImpl
+from superset.sqllab.schemas import (
+    ExecutePayloadSchema,
+    QueryExecutionResponseSchema,
+    sql_lab_get_results_schema,
+)
+from superset.sqllab.sql_json_executer import (
+    ASynchronousSqlJsonExecutor,
+    SqlJsonExecutor,
+    SynchronousSqlJsonExecutor,
+)
+from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+from superset.views.base import handle_api_exception
+from superset.views.base_api import (
+    BaseSupersetModelRestApi,
+    requires_json,
+    statsd_metrics,
+)
+
+config = app.config
+logger = logging.getLogger(__name__)
+
+
+class SqlLabRestApi(BaseSupersetModelRestApi):
+    datamodel = SQLAInterface(Query)
+
+    include_route_methods = {
+        "get_results",
+        "execute_sql_query",
+    }
+    resource_name = "sqllab"
+    allow_browser_login = True
+
+    class_permission_name = "Query"
+    method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP
+
+    execute_model_schema = ExecutePayloadSchema()
+
+    apispec_parameter_schemas = {
+        "sql_lab_get_results_schema": sql_lab_get_results_schema,
+    }
+    openapi_spec_tag = "SQL Lab"
+    openapi_spec_component_schemas = (
+        ExecutePayloadSchema,
+        QueryExecutionResponseSchema,
+    )
+
+    @expose("/results/")
+    @protect()
+    @safe
+    @statsd_metrics
+    @rison(sql_lab_get_results_schema)
+    @handle_api_exception

Review Comment:
   safe wraps only `BadRequest` error to 400 and a global `Exception` to 500.
   handle_api_exception wraps a set of Superset exceptions which are more specific



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org