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

   ## Problem
   
   `generate_chart` and `generate_explore_link` crash with:
   
   ```
   RuntimeError: Working outside of request context.
   ```
   
   This happens because `MCPCreateFormDataCommand` inherits 
`CreateFormDataCommand.run()`, which calls `flask.session.get("_id")` directly. 
Flask's `session` proxy requires an active HTTP request context, but MCP tools 
run in an **app context only** — there is no HTTP request.
   
   ## Root cause
   
   `MCPCreateFormDataCommand` already had a `_get_session_id()` override 
intended to fix this, but it was **never called**. The base class `run()` 
accesses `flask.session` directly rather than going through 
`self._get_session_id()`, making the override a no-op.
   
   ## Fix
   
   Override `run()` in `MCPCreateFormDataCommand` and replace 
`session.get("_id")` with `get_user_id()`. The session ID is only used as part 
of a Redis cache key for contextual form-data deduplication — substituting the 
user ID preserves that behaviour without requiring a request context.
   
   ## Test plan
   
   - [ ] Call `generate_chart` via MCP — confirm it no longer raises `Working 
outside of request context`
   - [ ] Call `generate_explore_link` via MCP — confirm explore URL is returned 
successfully
   - [ ] 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