codeant-ai-for-open-source[bot] commented on code in PR #45859:
URL: https://github.com/apache/superset/pull/45859#discussion_r4443109698


##########
superset/db_engine_specs/impala.py:
##########
@@ -152,7 +171,97 @@ def fetch_data(cls, cursor: Any, limit: int | None = None) 
-> list[tuple[Any, ..
                     cursor.fetchall()
             except Error as ex:
                 raise cls.get_dbapi_mapped_exception(ex) from ex
-        return super().fetch_data(cursor, limit)
+        operation = getattr(cursor, "_last_operation", None)
+        try:
+            query = _STOP_WATCHED_OPERATIONS.get(operation)
+        except TypeError:
+            # The cursor exposes no driver operation that could be watched.
+            query = None
+        if query is None:
+            return super().fetch_data(cursor, limit)
+        with cls._stop_checked_fetch(cursor, operation, query):
+            return super().fetch_data(cursor, limit)
+
+    @classmethod
+    @contextmanager
+    def _stop_checked_fetch(
+        cls, cursor: Any, operation: Any, query: Query
+    ) -> Iterator[None]:
+        """
+        Check for a committed stop before each result RPC of a SQL Lab query.
+
+        Impala reports a streaming SELECT as finished once its rows can be
+        fetched, so most of such a query runs while the worker reads results,
+        after ``handle_cursor`` stopped polling. The driver issues one fetch 
RPC
+        at a time, and while the coordinator's ``FETCH_ROWS_TIMEOUT_MS`` is
+        positive each returns within it even when no rows are ready, so a stop
+        goes unseen for at most about that plus the poll interval. A stop is 
applied
+        on the worker's own cursor and thread, as in ``handle_cursor``, so no
+        second connection or HTTP call is involved.
+        """
+        fetch = operation.fetch
+        # Read once: after a failed check the instance can be expired in a
+        # session that cannot load it, so reading it then would raise again.
+        query_id = query.id
+        interval = app.config["DB_POLL_INTERVAL_SECONDS"].get(cls.engine, 5)
+        last_check: float | None = None
+        checking = True
+
+        def fetch_unless_stopped(*args: Any, **kwargs: Any) -> Any:
+            nonlocal last_check, checking
+            now = time.monotonic()
+            if checking and (last_check is None or now - last_check >= 
interval):
+                last_check = now
+                try:
+                    stopped = cls._stop_requested(query)
+                except (SoftTimeLimitExceeded, SupersetTimeoutException):
+                    raise
+                except Exception:  # pylint: disable=broad-except
+                    # A metadata hiccup must not fail a query nobody stopped,
+                    # so the failed transaction must not outlive the check.
+                    try:
+                        db.session.rollback()  # pylint: 
disable=consider-using-transaction
+                    except Exception:  # pylint: disable=broad-except
+                        logger.debug("Query %s: rollback failed", query_id)
+                    logger.warning(
+                        "Query %s: stop check failed while fetching", query_id
+                    )
+                    checking = False

Review Comment:
   **Suggestion:** `checking = False` permanently disables stop checks after 
one transient metadata failure. If Stop commits later, the remaining result 
RPCs proceed without cancellation.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Logic error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=307ef12c09db456da682ba1f8dcda2d8&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=307ef12c09db456da682ba1f8dcda2d8&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/db_engine_specs/impala.py
   **Line:** 229:229
   **Comment:**
        *Logic Error: `checking = False` permanently disables stop checks after 
one transient metadata failure. If Stop commits later, the remaining result 
RPCs proceed without cancellation.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45859&comment_hash=5723e907997ada6f5a8abf268b3e64785b51ac3eda21f8dafaf20259e344e19c&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45859&comment_hash=5723e907997ada6f5a8abf268b3e64785b51ac3eda21f8dafaf20259e344e19c&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/db_engine_specs/impala.py:
##########
@@ -197,20 +306,9 @@ def handle_cursor(cls, cursor: Any, query: Query) -> None:
         try:
             status = cursor.status()
             while status in unfinished_states:
-                # End the read transaction first. Under REPEATABLE READ, 
refreshing
-                # inside one long transaction keeps returning the first 
snapshot,
-                # so a Stop committed by another request would never be seen.
-                db.session.commit()  # pylint: 
disable=consider-using-transaction
-                db.session.refresh(query)
-                # Stop was requested: either before a cancel handle was 
published
-                # (early-cancel flag) or through SQL Lab's stop, which persists
-                # STOPPED once cancel_query() succeeds.
-                if (
-                    query.extra.get(QUERY_EARLY_CANCEL_KEY)
-                    or query.status == QueryStatus.STOPPED
-                ):
+                if cls._stop_requested(query):

Review Comment:
   **Suggestion:** A `SupersetTimeoutException` here is swallowed by 
`handle_cursor`'s broad exception handler, so a timeout during polling can let 
query execution continue.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Possible bug`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6b21380ca539455a88578b02810a09c0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6b21380ca539455a88578b02810a09c0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/db_engine_specs/impala.py
   **Line:** 309:309
   **Comment:**
        *Possible Bug: A `SupersetTimeoutException` here is swallowed by 
`handle_cursor`'s broad exception handler, so a timeout during polling can let 
query execution continue.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45859&comment_hash=1cc99a8e390b97cfa09c59d3c70f314da1c7434094a8a9773b8df64603346b63&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45859&comment_hash=1cc99a8e390b97cfa09c59d3c70f314da1c7434094a8a9773b8df64603346b63&reaction=dislike'>๐Ÿ‘Ž</a>



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

  • [PR] fix(im... via GitHub
    • Re: [P... via GitHub
    • Re: [P... via GitHub
    • Re: [P... aminghadersohi (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... aminghadersohi (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... rebenitez1802 (via GitHub) via notifications
    • Re: [P... aminghadersohi (via GitHub) via notifications
    • Re: [P... rebenitez1802 (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... rebenitez1802 (via GitHub) via notifications
    • Re: [P... rebenitez1802 (via GitHub) via notifications

Reply via email to