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


##########
superset/db_engine_specs/impala.py:
##########
@@ -147,33 +149,29 @@ def handle_cursor(cls, cursor: Any, query: Query) -> None:
                 # the query was still executed
                 # modified in stop_query in views / core.py is reflected  here.
                 # stop query
-                if query.extra.get(QUERY_EARLY_CANCEL_KEY):
+                if query.extra.get(QUERY_EARLY_CANCEL_KEY) or query.status in (
+                    QueryStatus.STOPPED,
+                    QueryStatus.TIMED_OUT,
+                ):
                     cursor.cancel_operation()
                     cursor.close_operation()
                     cursor.close()

Review Comment:
   **Suggestion:** When `cancel_operation()` raises during a pending-to-running 
transition, execution skips both close calls and the outer handler returns, 
leaving the live cursor and operation open.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Resource leak`
   
   [![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=cfcee1ea7c5c41c6a57c1ae70f6df643&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=cfcee1ea7c5c41c6a57c1ae70f6df643&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:** 156:158
   **Comment:**
        *Resource Leak: When `cancel_operation()` raises during a 
pending-to-running transition, execution skips both close calls and the outer 
handler returns, leaving the live cursor and operation open.
   
   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%2F44737&comment_hash=0617746da1622a76a06b5fb341dc39eb557f7718e4e0825f02a4a2289257569e&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44737&comment_hash=0617746da1622a76a06b5fb341dc39eb557f7718e4e0825f02a4a2289257569e&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/db_engine_specs/impala.py:
##########
@@ -147,33 +149,29 @@ def handle_cursor(cls, cursor: Any, query: Query) -> None:
                 # the query was still executed
                 # modified in stop_query in views / core.py is reflected  here.
                 # stop query
-                if query.extra.get(QUERY_EARLY_CANCEL_KEY):
+                if query.extra.get(QUERY_EARLY_CANCEL_KEY) or query.status in (
+                    QueryStatus.STOPPED,
+                    QueryStatus.TIMED_OUT,
+                ):
                     cursor.cancel_operation()
                     cursor.close_operation()
                     cursor.close()
                     break
 
-                #  updates progress info by log
-                try:
-                    log = cursor.get_log() or ""
-                except Exception:  # pylint: disable=broad-except
-                    logger.warning("Call to GetLog() failed")
-                    log = ""
+                # Pending/initialized operations have no execution progress 
yet.
+                if status == "RUNNING_STATE":
+                    try:
+                        log = cursor.get_log() or ""
+                    except Exception:  # pylint: disable=broad-except
+                        logger.warning("Call to GetLog() failed")
+                        log = ""
 
-                if log:
-                    match = QUERY_PROGRESS_REGEX.match(log)
-                    if match:
+                    if match := QUERY_PROGRESS_REGEX.match(log):
                         progress = int(match.groupdict()["query_progress"])
-                    logger.debug(
-                        "Query %s: Progress total: %s", str(query_id), 
str(progress)
-                    )
-                    needs_commit = False
-                    if progress > query.progress:
-                        query.progress = progress
-                        needs_commit = True
-
-                    if needs_commit:
-                        db.session.commit()  # pylint: 
disable=consider-using-transaction
+                        logger.debug("Query %s: Progress total: %s", query_id, 
progress)
+                        if progress > query.progress:
+                            query.progress = progress
+                            db.session.commit()  # pylint: 
disable=consider-using-transaction

Review Comment:
   **Suggestion:** If a legacy query has `progress` set to NULL, comparing the 
parsed integer with it raises `TypeError` and silently stops all further 
cancellation polling.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Type 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=ced50e3a67284ed396b39e0668d928d5&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=ced50e3a67284ed396b39e0668d928d5&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:** 172:174
   **Comment:**
        *Type Error: If a legacy query has `progress` set to NULL, comparing 
the parsed integer with it raises `TypeError` and silently stops all further 
cancellation polling.
   
   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%2F44737&comment_hash=6effaf4a0ae22eed30d0ab8e8b60a407d6361917db7db1c806c1a0304a1a04f4&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44737&comment_hash=6effaf4a0ae22eed30d0ab8e8b60a407d6361917db7db1c806c1a0304a1a04f4&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/db_engine_specs/impala.py:
##########
@@ -147,33 +149,29 @@ def handle_cursor(cls, cursor: Any, query: Query) -> None:
                 # the query was still executed
                 # modified in stop_query in views / core.py is reflected  here.
                 # stop query
-                if query.extra.get(QUERY_EARLY_CANCEL_KEY):
+                if query.extra.get(QUERY_EARLY_CANCEL_KEY) or query.status in (
+                    QueryStatus.STOPPED,
+                    QueryStatus.TIMED_OUT,
+                ):

Review Comment:
   **Suggestion:** Under repeatable-read transactions, this status query can 
reuse a snapshot taken before Stop commits, so a persisted `STOPPED` or 
`TIMED_OUT` state is not observed.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Race condition`
   
   [![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=c65392d52ab4440e8da956a94b0d9b58&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=c65392d52ab4440e8da956a94b0d9b58&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:** 152:155
   **Comment:**
        *Race Condition: Under repeatable-read transactions, this status query 
can reuse a snapshot taken before Stop commits, so a persisted `STOPPED` or 
`TIMED_OUT` state is not observed.
   
   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%2F44737&comment_hash=b4f1c40431cc0668c849b0c8bf33b5863dd81c1dc932274ef02f5e61b2c2a84d&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44737&comment_hash=b4f1c40431cc0668c849b0c8bf33b5863dd81c1dc932274ef02f5e61b2c2a84d&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]

Reply via email to