aminghadersohi opened a new pull request, #38859:
URL: https://github.com/apache/superset/pull/38859
### SUMMARY
`generate_dashboard`, `add_chart_to_existing_dashboard`, and
`generate_chart` all re-fetch ORM objects after a commit using
`DashboardDAO.find_by_id()` or `ChartDAO.find_by_id()`. In multi-tenant
environments the DAO may use a different scoped session that is already
invalidated after commit, causing **"Can't reconnect until invalid transaction
is rolled back"**.
This PR replaces the DAO re-fetch with a direct `db.session.query()` call on
the current session, which avoids the stale-session problem.
Also narrows the broad `except Exception` in
`add_chart_to_existing_dashboard` and `generate_chart` to catch only the
specific exceptions that can occur (`CommandException`, `SQLAlchemyError`,
`KeyError`, `ValueError`).
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - backend-only change
### TESTING INSTRUCTIONS
1. Run the MCP service unit tests:
```
pytest tests/unit_tests/mcp_service/ -x
```
2. Test `generate_dashboard`, `add_chart_to_existing_dashboard`, and
`generate_chart` MCP tools in a multi-tenant environment
3. Verify that the tools no longer fail with "Can't reconnect until invalid
transaction is rolled back"
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] 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]