michael-s-molina opened a new pull request, #37252:
URL: https://github.com/apache/superset/pull/37252

   ### SUMMARY
   Fixes a bug where the MCP service would corrupt Flask-AppBuilder's shared 
`appbuilder` singleton, causing `BuildError: Could not build url for endpoint 
'None.login'` errors when accessing Superset.
   
   **Root Cause:**
   
   PR #37190 (`fix(mcp): push Flask app context in mcp_auth_hook for tool 
execution`) added `from superset.mcp_service.flask_singleton import 
get_flask_app` to `auth.py`. During main app initialization, when MCP tools are 
decorated with `@tool` (which uses `mcp_auth_hook`), this import triggers 
`flask_singleton.py` to be loaded. The `flask_singleton.py` module then calls 
`create_app()` creating a second Flask app that re-initializes the shared 
`appbuilder` singleton.
   
   When `appbuilder.init_app()` is called a second time:
   1. Flask-AppBuilder's `add_view_no_menu()` detects the view class is already 
registered
   2. It returns a **new instance** without calling `create_blueprint()` (which 
sets the `endpoint` attribute)
   3. The view's `endpoint` remains `None`
   4. When the main app tries to build URLs (e.g., `get_url_for_login`), it 
fails with `BuildError`
   
   **The Fix:**
   
   Modified `superset/mcp_service/flask_singleton.py` to check if 
`appbuilder.app` is already initialized. If so, it reuses the existing Flask 
app instead of creating a new one via `create_app()`. This prevents corruption 
of the shared appbuilder singleton.
   
   ```python
   # Before: Always created a new app
   _temp_app = create_app()
   
   # After: Reuse existing app if appbuilder is already initialized
   if appbuilder.app is not None:
       app = appbuilder.app
   else:
       _temp_app = create_app()
       # ... initialization code
   ```
   
   ### TESTING INSTRUCTIONS
   1. Enable MCP service in your Superset configuration
   2. Start Superset in debug mode: `superset run -p 8088 --reload --debugger`
   3. Navigate to `http://localhost:8088/superset/welcome/`
   4. Verify the login page loads without errors
   5. Verify you can log in successfully
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


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