You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "kgabryje (via GitHub)" <gi...@apache.org> on 2026/03/20 16:20:30 UTC

[PR] fix(mcp): fix detached Slice instance error in chart/dashboard serialization [superset]

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

   ### SUMMARY
   
   Fixes "Instance `<Slice>` is not bound to a Session" error in MCP tools (`generate_chart`, `generate_dashboard`, `add_chart_to_existing_dashboard`) by re-fetching ORM objects with eager-loaded relationships before serialization.
   
   **Root cause:** The `Slice` model's `owners` and `tags` relationships use default lazy loading. After `CreateChartCommand.run()` / `CreateDashboardCommand.run()` commits the transaction, SQLAlchemy expires the instances. When `serialize_chart_object()` later accesses these lazy-loaded attributes, the refresh fails because the instance is no longer bound to an active session.
   
   **Fix:** Re-fetch objects with `subqueryload(Slice.owners)` and `subqueryload(Slice.tags)` before serialization — the same pattern already used in `get_chart_info` and `get_dashboard_info`.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — backend-only fix, no UI changes.
   
   ### TESTING INSTRUCTIONS
   1. Use the `generate_chart` MCP tool with `save_chart=True`
   2. Use the `generate_dashboard` MCP tool with valid chart IDs
   3. Use the `add_chart_to_existing_dashboard` MCP tool
   4. Verify all three return chart/dashboard info with `owners` and `tags` populated instead of raising a detached instance error
   
   ### ADDITIONAL INFORMATION
   - [ ] 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: 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): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje merged PR #38767:
URL: https://github.com/apache/superset/pull/38767


-- 
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): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on PR #38767:
URL: https://github.com/apache/superset/pull/38767#issuecomment-4099444356

   > We should not be querying data directly in the tools, should we?
   
   I think not, but it's an existing pattern in mcp tools


-- 
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): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on PR #38767:
URL: https://github.com/apache/superset/pull/38767#issuecomment-4099513270

   @Antonio-RiveroMartnez updated to use DAOs 😄 


-- 
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): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38767:
URL: https://github.com/apache/superset/pull/38767#issuecomment-4099856129

   **Bito Automatic Review Skipped – PR Already Merged**<br/><br/>Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.<br/>No action is needed if you didn't intend to review it. To get a review, you can type `/review` in a comment and save it


-- 
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): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #38767:
URL: https://github.com/apache/superset/pull/38767#issuecomment-4099369981

   ## **Sequence Diagram**
   
   This PR fixes detached ORM errors by reloading saved chart or dashboard entities with related owners and tags before serialization. The updated flow ensures response building uses fully hydrated objects after command commits.
   
   ```mermaid
   sequenceDiagram
       participant Client
       participant MCPTool
       participant Command
       participant Database
       participant Serializer
   
       Client->>MCPTool: Request generate or update dashboard or chart
       MCPTool->>Database: Load chart objects with owners and tags
       Database-->>MCPTool: Chart ORM objects
       MCPTool->>Command: Run create or update command
       Command->>Database: Commit entity changes
       Database-->>MCPTool: Return saved entity id
       MCPTool->>Database: Reload entity with related owners tags and slices
       Database-->>MCPTool: Hydrated entity
       MCPTool->>Serializer: Serialize hydrated entity for response
       Serializer-->>Client: Return chart or dashboard info
   ```
   
   ---
   *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


Re: [PR] fix(mcp): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38767:
URL: https://github.com/apache/superset/pull/38767#issuecomment-4099364547

   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): fix detached Slice instance error in chart/dashboard serialization [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #38767:
URL: https://github.com/apache/superset/pull/38767#issuecomment-4099433870

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/38767?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `0%` with `13 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 63.73%. Comparing base ([`c2a2191`](https://app.codecov.io/gh/apache/superset/commit/c2a21915ff3695319d62879050a520726d92c88b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`49dcdac`](https://app.codecov.io/gh/apache/superset/commit/49dcdac770fa50f1c1ff1ae52004dc941e761571?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/38767?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [.../dashboard/tool/add\_chart\_to\_existing\_dashboard.py](https://app.codecov.io/gh/apache/superset/pull/38767?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdashboard%2Ftool%2Fadd_chart_to_existing_dashboard.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGFzaGJvYXJkL3Rvb2wvYWRkX2NoYXJ0X3RvX2V4aXN0aW5nX2Rhc2hib2FyZC5weQ==) | 0.00% | [5 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/38767?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/chart/tool/generate\_chart.py](https://app.codecov.io/gh/apache/superset/pull/38767?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fgenerate_chart.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC9nZW5lcmF0ZV9jaGFydC5weQ==) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/38767?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...t/mcp\_service/dashboard/tool/generate\_dashboard.py](https://app.codecov.io/gh/apache/superset/pull/38767?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdashboard%2Ftool%2Fgenerate_dashboard.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGFzaGJvYXJkL3Rvb2wvZ2VuZXJhdGVfZGFzaGJvYXJkLnB5) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/38767?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   :x: Your project check has failed because the head coverage (99.92%) is below the target coverage (100.00%). You can increase the head coverage or adjust the [target](https://docs.codecov.com/docs/commit-status#target) coverage.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #38767      +/-   ##
   ==========================================
   - Coverage   65.30%   63.73%   -1.57%     
   ==========================================
     Files        1819     2532     +713     
     Lines       72745   129980   +57235     
     Branches    23266    30065    +6799     
   ==========================================
   + Hits        47505    82844   +35339     
   - Misses      25240    45664   +20424     
   - Partials        0     1472    +1472     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/38767/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/38767/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `61.61% <0.00%> (?)` | |
   | [python](https://app.codecov.io/gh/apache/superset/pull/38767/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `61.72% <0.00%> (?)` | |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/38767/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `61.24% <0.00%> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/38767?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


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