fix(mcp): add try/except around DAO re-fetch to handle session errors in multi-tenant#38859
Conversation
Code Review Agent Run #6185a2Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Sequence DiagramThis PR updates MCP save flows to re-load dashboards and charts using the active db session instead of DAO lookups, preventing stale session failures after commit in multi-tenant setups. It also limits top-level error handling to expected exception types for clearer failure responses. sequenceDiagram
participant Client
participant MCP Tool
participant Command
participant DB Session
participant Serializer
Client->>MCP Tool: Request to generate or update dashboard or chart
MCP Tool->>Command: Save or update entity
Command-->>MCP Tool: Return saved entity
MCP Tool->>DB Session: Requery same entity with eager relations
alt Requery succeeds
DB Session-->>MCP Tool: Session bound entity
else Requery fails
DB Session-->>MCP Tool: Database error
MCP Tool->>MCP Tool: Fallback to saved entity
end
MCP Tool->>Serializer: Serialize entity for response
MCP Tool-->>Client: Return success or specific handled error
Generated by CodeAnt AI |
Codecov Report❌ Patch coverage is ❌ Your project status has failed because the head coverage (99.85%) is below the target coverage (100.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #38859 +/- ##
==========================================
- Coverage 65.54% 64.42% -1.13%
==========================================
Files 1823 2536 +713
Lines 73154 130719 +57565
Branches 23437 30308 +6871
==========================================
+ Hits 47951 84211 +36260
- Misses 25203 45042 +19839
- Partials 0 1466 +1466
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Review Agent Run #fb4952Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #a90f89Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
…ommit In multi-tenant environments, the DAO re-fetch after commit can fail with "Can't reconnect until invalid transaction is rolled back". The previous fallback to the "original" object was unsound — the original is bound to the same dead session, so accessing lazy-loaded relationships (tags, owners, slices) would trigger DetachedInstanceError. Fix: follow the update_chart.py pattern — when the DAO re-fetch fails, build a minimal response from scalar attributes that are already loaded on the object (id, title, url, etc.), skipping relationship fields entirely. This avoids any further session access. Changes: - generate_dashboard: return minimal DashboardInfo on re-fetch failure - add_chart_to_existing_dashboard: same, plus position info - generate_chart: build minimal chart_data dict, skip serialize_chart_object - Move SQLAlchemyError/CommandException imports before try blocks - Narrow outer except clauses to specific exception types - Update tests to assert minimal response content (id, url, empty relationships)
0cd9774 to
172131c
Compare
|
Addressing review comments — all squashed into single commit 172131c: Re: codeant bot concern about Re: "i am looking into a better solution" (stale session fallback): All prior review comments (rollback, import ordering, test coverage) were addressed in earlier commits and are now squashed into this single commit. |
Remove parentheses from @pytest.mark.asyncio() and @pytest.fixture() decorators to comply with ruff 0.9.7 PT023/PT001 rules.
There was a problem hiding this comment.
Code Review Agent Run #657907
Actionable Suggestions - 1
-
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py - 1
- Incorrect position info dict · Line 466-470
Review Details
-
Files reviewed - 5 · Commit Range:
172131c..c4da7d6- superset/mcp_service/chart/tool/generate_chart.py
- superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py
- superset/mcp_service/dashboard/tool/generate_dashboard.py
- tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py
- tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_generation.py
-
Files skipped - 0
-
Tools
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
- MyPy (Static Code Analysis) - ✔︎ Successful
- Astral Ruff (Static Code Analysis) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.
Documentation & Help
User description
Summary
DashboardDAO.find_by_id()/ChartDAO.find_by_id()re-fetch calls intry/except SQLAlchemyErrorwithdb.session.rollback()fallback ingenerate_dashboard,add_chart_to_existing_dashboard, andgenerate_chartexcept Exceptionto specific exceptions (CommandException,SQLAlchemyError,KeyError,ValueError) ingenerate_chartandadd_chart_to_existing_dashboardlogger.warning()withexc_info=Truein re-fetch failure paths for operational visibilityNonevalues fromserialize_chart_objectinadd_chart_to_existing_dashboardchart listTest plan
generate_dashboardon staging — created dashboard successfullyadd_chart_to_existing_dashboardon staging — added chart successfullygenerate_charton a workspace with working examples DBCodeAnt-AI Description
Keep dashboard and chart creation working after commit in multi-tenant sessions
What Changed
Impact
✅ Fewer dashboard creation failures✅ Fewer chart save errors after commit✅ Fewer broken add-chart actions in multi-tenant workspaces💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.