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

   <!---
   Please write the PR title following the conventions at 
https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   Fixes two issues in the MCP chatbot/SQL execution flow:
   1. Cached query results failing with bytes/encoding errors — The result 
cache was storing raw pandas DataFrames (which get pickled by some cache 
backends into bytes). On retrieval, the code assumed thedata was always a 
DataFrame, causing errors when encountering bytes. This PR serializes 
DataFrames to a JSON-safe dict format ({"records": [...], "columns": [...]}) 
before caching, and adds a _deserialize_cached_data() method that gracefully 
handles all formats (dict, DataFrame, None, and bytes as a cache miss) — 
intentionally avoiding pickle deserialization to prevent code-execution attacks 
from a compromised cache backend.
   2. MCP middleware ordering was reversed — FastMCP 2.14+ changed how 
middleware is chained (uses reversed(middleware)), so the first-added 
middleware is now outermost. The middleware list ordering in server.py was 
updated to reflect this: GlobalErrorHandler → Logging → SizeGuard → Caching 
(outermost → innermost).
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
     1. Start Superset with MCP enabled
     2. Run a SQL query via the MCP chatbot that returns results
     4. Run the same query again — it should hit the cache and return correctly 
(no bytes/encoding errors)
     5. Verify DML queries (INSERT/UPDATE) that return no data also work from 
cache
     6. Verify middleware logging shows correct nesting order (error handler 
outermost)
   
   ### 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