congmnguyen opened a new pull request, #38867:
URL: https://github.com/apache/superset/pull/38867

   ## Summary
   
   - Replaces `appbuilder._session is not None` with `has_app_context()` to 
detect whether a Flask app is already running when `flask_singleton.py` is 
imported
   - Removes the now-unreachable `elif appbuilder_initialized` branch that 
raised a `RuntimeError`
   - Eliminates the `from superset.extensions import appbuilder` import, which 
was only needed for the `_session` check
   
   ## Motivation
   
   `appbuilder._session` is a private Flask-AppBuilder implementation detail. 
Reading it is fragile:
   - It may not exist in all FAB versions, causing `AttributeError`
   - It causes a spurious second `create_app()` call that corrupts shared 
appbuilder state (views, security manager, etc.)
   
   When the CLI's `FlaskGroup` invokes `superset mcp run`, it already pushes a 
Flask app context before the subcommand runs. `has_app_context()` is Flask's 
canonical, public API for detecting this — no FAB internals needed.
   
   The eliminated `elif` branch (`appbuilder initialized but no app context`) 
is unreachable in practice: `appbuilder.init_app()` always runs inside an app 
context, so if appbuilder is initialized an app context must already exist.
   
   ## Test plan
   
   - [ ] Run `superset mcp run` and confirm it starts without error
   - [ ] Confirm MCP tools are listed at `http://localhost:5008/mcp`
   - [ ] Confirm existing unit tests pass


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