sadpandajoe commented on code in PR #36350:
URL: https://github.com/apache/superset/pull/36350#discussion_r3824469976


##########
superset/common/query_context_processor.py:
##########
@@ -132,7 +139,56 @@ def get_df_payload(
                         )
                     )
 
-                query_result = self.get_query_result(query_obj)
+                # Create a persisted Query row for chart queries so we can 
expose a
+                # client_id and allow cancellation later. This mirrors SQL 
Lab's
+                # behavior; it is best-effort and only created if the 
datasource has
+                # an underlying database.
+                if (
+                    hasattr(self._qc_datasource, "database")
+                    and getattr(self._qc_datasource, "database", None) is not 
None
+                ):
+                    try:
+                        from uuid import uuid4
+
+                        from superset.models.sql_lab import Query as 
SqlLabQuery
+                        from superset.utils.core import get_user_id
+
+                        # Use client_id if provided by the client (e.g., 
frontend)
+                        provided_client_id = (
+                            self._query_context.cache_values.get("client_id")
+                            if isinstance(self._query_context.cache_values, 
dict)
+                            else None
+                        )
+
+                        client_id = provided_client_id or uuid4().hex[:11]
+
+                        # If a Query with this client_id already exists, reuse 
it.

Review Comment:
   Stop becomes available before this row is registered. If the user stops 
immediately (or an async job has not begun), the stop request gets not found 
and records no cancellation intent; this request then creates the row and runs 
the database query anyway. Should cancellation be registered before the work is 
queued, or should a not-found stop be retained and applied when the row is 
created?



##########
superset-frontend/src/explore/components/ExploreViewContainer/index.tsx:
##########
@@ -563,9 +564,22 @@ function ExploreViewContainer(props: 
ExploreViewContainerProps) {
   );
 
   function onStop() {
-    if (props.chart && props.chart.queryController) {
+    // Method 1: Abort the in-flight HTTP request using AbortController
+    if (props.chart?.queryController) {
       props.chart.queryController.abort();
     }
+
+    // Method 2: Send stop request to backend if we have a query ID
+    const queryId = props.chart?.latestQueryId;
+    if (queryId) {
+      SupersetClient.post({

Review Comment:
   This calls the SQL Lab Query API, whose protected `stop_query` method 
requires the Query permission, while Explore users only need chart permissions. 
A chart-only role can therefore abort the browser request but receives 403 
here, leaving the database query running. Should this use an Explore-authorized 
cancellation endpoint or grant the required permission with the feature?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to