aminghadersohi commented on code in PR #38934:
URL: https://github.com/apache/superset/pull/38934#discussion_r3009613943
##########
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py:
##########
@@ -435,25 +435,60 @@ def add_chart_to_existing_dashboard(
# Re-fetch the dashboard with eager-loaded relationships to avoid
# "Instance is not bound to a Session" errors when serializing
- # chart .tags and .owners.
+ # chart .tags and .owners. The preceding command.run() commit may
+ # invalidate the session in multi-tenant environments; on failure,
+ # return a minimal response using only scalar attributes that are
+ # already loaded — relationship fields (owners, tags, slices) would
+ # trigger lazy-loading on the same dead session.
from sqlalchemy.orm import subqueryload
- from superset.daos.dashboard import DashboardDAO
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
- updated_dashboard = (
- DashboardDAO.find_by_id(
+ try:
+ updated_dashboard = (
+ DashboardDAO.find_by_id(
+ updated_dashboard.id,
+ query_options=[
+
subqueryload(Dashboard.slices).subqueryload(Slice.owners),
+
subqueryload(Dashboard.slices).subqueryload(Slice.tags),
+ subqueryload(Dashboard.owners),
+ subqueryload(Dashboard.tags),
+ ],
+ )
+ or updated_dashboard
+ )
+ except SQLAlchemyError:
+ logger.warning(
+ "Re-fetch of dashboard %s failed; returning minimal response",
updated_dashboard.id,
- query_options=[
- subqueryload(Dashboard.slices).subqueryload(Slice.owners),
- subqueryload(Dashboard.slices).subqueryload(Slice.tags),
- subqueryload(Dashboard.owners),
- subqueryload(Dashboard.tags),
- ],
+ exc_info=True,
+ )
+ try:
+ db.session.rollback() # pylint:
disable=consider-using-transaction
+ except SQLAlchemyError:
+ logger.warning(
+ "Database rollback failed during dashboard re-fetch error
handling",
+ exc_info=True,
+ )
+ dashboard_url = (
+
f"{get_superset_base_url()}/superset/dashboard/{updated_dashboard.id}/"
+ )
+ position_info = {
+ "row": row_key,
+ "chart_key": chart_key,
+ "row_key": row_key,
+ }
+ return AddChartToDashboardResponse(
+ dashboard=DashboardInfo(
+ id=updated_dashboard.id,
+ dashboard_title=updated_dashboard.dashboard_title,
+ url=dashboard_url,
+ ),
Review Comment:
Fixed in 218c5fb0e0 — fallback `DashboardInfo` now populates `chart_count`
from `all_chart_objects` (already in-memory) and `published` from
`updated_dashboard.published` (safe scalar attribute).
--
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]