You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "congmnguyen (via GitHub)" <gi...@apache.org> on 2026/03/26 02:59:08 UTC
[PR] fix(mcp): use has_app_context() instead of private appbuilder._session check [superset]
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): use has_app_context() instead of private appbuilder._session check [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #38867:
URL: https://github.com/apache/superset/pull/38867#issuecomment-4131269845
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | e1e7f135f6c4821add8315f57ed59817ba9d95e2 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/69c4a0fc3c33ab000831da71 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-38867--superset-docs-preview.netlify.app](https://deploy-preview-38867--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-38867--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): use has_app_context() instead of private appbuilder._session check [superset]
Posted by "congmnguyen (via GitHub)" <gi...@apache.org>.
congmnguyen closed pull request #38867: fix(mcp): use has_app_context() instead of private appbuilder._session check
URL: https://github.com/apache/superset/pull/38867
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): use has_app_context() instead of private appbuilder._session check [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38867:
URL: https://github.com/apache/superset/pull/38867#issuecomment-4131246470
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): use has_app_context() instead of private appbuilder._session check [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #38867:
URL: https://github.com/apache/superset/pull/38867#issuecomment-4131249923
## **Sequence Diagram**
This PR changes the MCP Flask singleton to detect an existing Flask app via has_app_context and reuse it when running inside Superset, only creating a new app when no app context exists, avoiding double initialization and fragile appbuilder internals.
```mermaid
sequenceDiagram
participant CLI
participant FlaskCLI
participant MCPModule
participant FlaskApp
CLI->>FlaskCLI: Run superset mcp run
FlaskCLI->>FlaskApp: Create app and push context
FlaskCLI->>MCPModule: Import MCP flask_singleton
MCPModule->>MCPModule: Check has_app_context
alt App context exists
MCPModule->>FlaskApp: Reuse current_app for MCP service
else No app context
MCPModule->>FlaskApp: Create new Flask app for MCP service
end
```
---
*Generated by [CodeAnt AI](https://codeant.ai)*
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org