You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/10/01 08:58:41 UTC

[GitHub] [incubator-superset] dpgaspar commented on a change in pull request #10836: feat: Stop pending queries when user close dashboard

dpgaspar commented on a change in pull request #10836:
URL: https://github.com/apache/incubator-superset/pull/10836#discussion_r498085128



##########
File path: superset/charts/api.py
##########
@@ -503,6 +504,50 @@ def data(self) -> Response:
 
         return response
 
+    @expose("/data/stop", methods=["POST"])
+    @event_logger.log_this
+    @protect()
+    @safe
+    @statsd_metrics
+    def data_stop(self) -> Response:
+        """
+        Takes a dashboard id and tries to cancel all associated chart data requests
+        issued by the user.
+        ---
+        post:
+          description: >-
+            Takes a dashboard id and tries to cancel all associated chart data requests
+            issued by the user
+          requestBody:
+            description: >-
+              The dashboard id.
+            required: true
+            content:
+              application/json:
+                schema:
+                  $ref: "#/components/schemas/ChartDataStopSchema"
+          responses:
+            200:
+              description: Pending dashboard queries terminated
+              content:
+                application/json:
+                  schema:
+                    type: object
+            400:
+              $ref: '#/components/responses/400'
+            500:
+              $ref: '#/components/responses/500'
+        """
+        if request.is_json:
+            json_body = request.json
+            dashboard_id = json_body.get("dashboard_id")
+            if not dashboard_id:
+                return self.response(400, message="dashboard_id missing in body")
+            hook = current_app.config["STOP_DASHBOARD_PENDING_QUERIES_HOOK"]
+            hook(dashboard_id, g.user.username)

Review comment:
       `@protect` or `@has_access` does not guarantee we a have a user, since it's possible for a public/non authenticated user to access this resource. It's probably very unlikely that a `Public` role has access to this resource, but now it's possible to set `PUBLIC_ROLE_LIKE = "Admin"`.

##########
File path: superset/charts/api.py
##########
@@ -503,6 +504,50 @@ def data(self) -> Response:
 
         return response
 
+    @expose("/data/stop", methods=["POST"])
+    @event_logger.log_this
+    @protect()
+    @safe
+    @statsd_metrics
+    def data_stop(self) -> Response:
+        """
+        Takes a dashboard id and tries to cancel all associated chart data requests
+        issued by the user.
+        ---
+        post:
+          description: >-
+            Takes a dashboard id and tries to cancel all associated chart data requests
+            issued by the user
+          requestBody:
+            description: >-
+              The dashboard id.
+            required: true
+            content:
+              application/json:
+                schema:
+                  $ref: "#/components/schemas/ChartDataStopSchema"
+          responses:
+            200:
+              description: Pending dashboard queries terminated
+              content:
+                application/json:
+                  schema:
+                    type: object

Review comment:
       Can you add more detail on the data structure of the response?

##########
File path: superset/charts/api.py
##########
@@ -503,6 +504,50 @@ def data(self) -> Response:
 
         return response
 
+    @expose("/data/stop", methods=["POST"])

Review comment:
       optional: maybe it would be simpler to set this endpoint to `/data/stop/<id>` HTTP POST or PUT, no need for a payload 

##########
File path: superset/config.py
##########
@@ -309,6 +313,8 @@ def _try_json_readsha(  # pylint: disable=unused-argument
     "TAGGING_SYSTEM": False,
     "SQLLAB_BACKEND_PERSISTENCE": False,
     "LISTVIEWS_DEFAULT_CARD_VIEW": False,
+    # stop pending queries when user close/reload dashboard in browser
+    "STOP_DASHBOARD_PENDING_QUERIES": False,

Review comment:
       If this is behind a feature flag we can go even further and not register the endpoint at all. Take a look at: https://github.com/apache/incubator-superset/blob/master/superset/dashboards/api.py#L173
   




----------------------------------------------------------------
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.

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