codeant-ai-for-open-source[bot] commented on code in PR #45860:
URL: https://github.com/apache/superset/pull/45860#discussion_r4442953571
##########
superset/tasks/query_cancel.py:
##########
@@ -101,21 +149,47 @@ def capture_cancel_id(sink: "Callable[[Any], None]") ->
Iterator[None]:
_cancel_id_sink.reset(token)
-def notify_cursor(cursor: Any) -> None:
- """Hand the live cursor to the active sink, if any.
-
- Called from ``get_df`` before the query executes. Best-effort: a capture
- failure must never break query execution โ it only forfeits cancellability.
+def notify_cursor(
+ cursor: Any,
+ database: "Database",
+ phase: CursorPhase = CursorPhase.OPENED,
+) -> None:
+ """Hand the live cursor, its database and its phase to the active sink, if
any.
+
+ Called from ``get_df`` on the thread that runs the cursor. Best-effort: a
+ capture failure must never break query execution โ it only forfeits
+ cancellability. The exception is ``ChartQueryAbortedError``, which a sink
+ raises to stop the task's remaining work once its abort is accepted.
"""
sink = _cancel_id_sink.get()
if sink is None:
return
try:
- sink(cursor)
+ sink(cursor, database, phase)
+ except ChartQueryAbortedError:
+ raise
except Exception: # noqa: BLE001 pylint: disable=broad-except
logger.warning("Cancel-id capture failed", exc_info=True)
+@contextmanager
+def tracked_cursor(cursor: Any, database: "Database") -> Iterator[None]:
+ """Notify the active sink that a cursor opened and, on exit, that it was
released.
+
+ The release is notified however the cursor's statements end, so a task
never
+ keeps the cancel id of an operation that is over.
+ """
+ notify_cursor(cursor, database)
+ phase = CursorPhase.RELEASED
+ try:
+ yield
+ except Exception:
+ phase = CursorPhase.FAILED
+ raise
+ finally:
+ notify_cursor(cursor, database, phase)
Review Comment:
**Suggestion:** If an abort arrives during the final fetch but cancellation
loses the race, this release notification only clears the handle, so the task
can cache a result after abort.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Logic error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=047dfe8f2ceb4074a33894ac2488f615&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=047dfe8f2ceb4074a33894ac2488f615&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/tasks/query_cancel.py
**Line:** 189:190
**Comment:**
*Logic Error: If an abort arrives during the final fetch but
cancellation loses the race, this release notification only clears the handle,
so the task can cache a result after abort.
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%2F45860&comment_hash=ce281b048cab992c932ecf603bdf049d17ed5997a78c5fa10a545b62998975f2&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45860&comment_hash=ce281b048cab992c932ecf603bdf049d17ed5997a78c5fa10a545b62998975f2&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]