aminghadersohi commented on code in PR #38859:
URL: https://github.com/apache/superset/pull/38859#discussion_r2994612668
##########
superset/mcp_service/dashboard/tool/add_chart_to_existing_dashboard.py:
##########
@@ -426,25 +430,54 @@ 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,
+ )
+ db.session.rollback()
+ 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,
+ }
Review Comment:
Good catch on the duplicate key pattern, but this is intentionally
consistent with the existing happy path at line 528 which uses the same
structure: `{"row": row_key, "chart_key": chart_key, "row_key": row_key}`.
Changing only the fallback would create an inconsistency. If we want to include
`column_key`, that should be a separate change that updates both paths.
--
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]