codeant-ai-for-open-source[bot] commented on code in PR #45478:
URL: https://github.com/apache/superset/pull/45478#discussion_r4317662967
##########
superset/coordination/base.py:
##########
@@ -525,6 +533,19 @@ def wake() -> None:
return SignalListener(thread, stop_event, wake=wake)
+ @staticmethod
+ def _capture_background_context() -> Callable[[], ContextManager[Any]]:
+ """Snapshot caller-thread context for a background thread to re-enter.
+
+ Resolves ``BACKGROUND_THREAD_CONTEXT_FACTORY`` on the calling thread
(where
+ the request/task context is live) and returns the callable the
background
+ thread uses to enter an equivalent context. Without a configured
factory
+ the returned context manager is a no-op, leaving the thread to push a
bare
+ app context per call as before.
+ """
+ factory = current_app.config.get("BACKGROUND_THREAD_CONTEXT_FACTORY")
Review Comment:
**Suggestion:** Without a Flask app context, even the default `None` factory
lookup raises `RuntimeError`, so otherwise valid no-backend listeners fail
before their thread starts.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Api mismatch`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8c052f7d1785482fa15eebf6146d36d2&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=8c052f7d1785482fa15eebf6146d36d2&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/coordination/base.py
**Line:** 546:546
**Comment:**
*Api Mismatch: Without a Flask app context, even the default `None`
factory lookup raises `RuntimeError`, so otherwise valid no-backend listeners
fail before their thread starts.
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%2F45478&comment_hash=02ef74734e92ae5a9ee76ccd5b6010e795181b17870c4fb58d7accaae857aa1d&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45478&comment_hash=02ef74734e92ae5a9ee76ccd5b6010e795181b17870c4fb58d7accaae857aa1d&reaction=dislike'>๐</a>
##########
superset/coordination/base.py:
##########
@@ -497,9 +498,16 @@ def listen_for_signal(
:param name: optional thread name suffix for logging.
"""
stop_event = threading.Event()
+ enter_context = cls._capture_background_context()
+
+ def run() -> None:
+ with enter_context():
+ cls._run_listen_loop(
+ channel, check, on_signal, stop_event, poll_interval
+ )
Review Comment:
**Suggestion:** When the factory supplies an app context, this outer scope
makes `_in_app_context` skip per-poll teardown, so the thread-scoped SQLAlchemy
session can retain a connection for the task's lifetime.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Resource leak`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ee8d6c4f2ced489f9d423c9cf01ba7a6&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=ee8d6c4f2ced489f9d423c9cf01ba7a6&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/coordination/base.py
**Line:** 504:507
**Comment:**
*Resource Leak: When the factory supplies an app context, this outer
scope makes `_in_app_context` skip per-poll teardown, so the thread-scoped
SQLAlchemy session can retain a connection for the task's lifetime.
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%2F45478&comment_hash=0adba866bcd39a7fd4f9fb8fe8fac35de42f1ccb024f3cb18d6ea5b5341facd1&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45478&comment_hash=0adba866bcd39a7fd4f9fb8fe8fac35de42f1ccb024f3cb18d6ea5b5341facd1&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]