mikebridge commented on code in PR #45482:
URL: https://github.com/apache/superset/pull/45482#discussion_r4327816575
##########
superset/versioning/restore.py:
##########
@@ -742,11 +748,29 @@ def _restore_dashboard_membership(dashboard: Any,
transaction_id: int) -> list[i
if window.contains(transaction_id)
}
)
- if not member_ids:
- dashboard.slices = []
- return []
-
- live_slices =
db.session.query(Slice).filter(Slice.id.in_(member_ids)).all()
+ # Archived charts must be visible both to the lookup and to the
+ # assignment, which diffs against the current membership. A membership
+ # loaded through ``dashboard.slices`` misses archived members, even inside
+ # the bypass, because the dashboard's own load carried the filter, so the
+ # flush would keep or re-insert their rows. Read it from the association
+ # table instead and diff against that.
+ with skip_visibility_filter(db.session, Slice):
+ current_slices: list[Slice] = (
+ db.session.query(Slice)
+ .join(dashboard_slices, dashboard_slices.c.slice_id == Slice.id)
+ .filter(dashboard_slices.c.dashboard_id == dashboard.id)
+ .all()
+ )
+ live_slices: list[Slice] = (
+ db.session.query(Slice).filter(Slice.id.in_(member_ids)).all()
+ if member_ids
+ else []
+ )
+ # Installing the baseline drops any unflushed change to the collection.
+ # There is none here: the dashboard revert restores no relationships, and
+ # single_flush_scope holds back autoflush until the restore is done.
+ set_committed_value(dashboard, "slices", current_slices)
Review Comment:
Added the guard as suggested, with a test that a pending change to
dashboard.slices makes the restore refuse instead of dropping it, in 1f54dced2b.
##########
superset/versioning/restore.py:
##########
@@ -742,11 +748,29 @@ def _restore_dashboard_membership(dashboard: Any,
transaction_id: int) -> list[i
if window.contains(transaction_id)
}
)
- if not member_ids:
- dashboard.slices = []
- return []
-
- live_slices =
db.session.query(Slice).filter(Slice.id.in_(member_ids)).all()
+ # Archived charts must be visible both to the lookup and to the
+ # assignment, which diffs against the current membership. A membership
+ # loaded through ``dashboard.slices`` misses archived members, even inside
+ # the bypass, because the dashboard's own load carried the filter, so the
+ # flush would keep or re-insert their rows. Read it from the association
+ # table instead and diff against that.
+ with skip_visibility_filter(db.session, Slice):
+ current_slices: list[Slice] = (
+ db.session.query(Slice)
+ .join(dashboard_slices, dashboard_slices.c.slice_id == Slice.id)
+ .filter(dashboard_slices.c.dashboard_id == dashboard.id)
+ .all()
+ )
+ live_slices: list[Slice] = (
+ db.session.query(Slice).filter(Slice.id.in_(member_ids)).all()
+ if member_ids
+ else []
Review Comment:
Added a case where the version has no charts and the only member is
archived, in 1f54dced2b. It fails on master's restore and passes here.
##########
docs/docs/using-superset/version-history.mdx:
##########
@@ -282,8 +282,10 @@ worth knowing:
you moved away from. Returning to one of those states depends on its history
still being available; retention and permanent deletion can remove it.
- **A dashboard restore may be partial.** If the version referenced charts that
- have since been deleted, the layout is restored without them and Superset
- tells you how many were not reattached.
+ have since been permanently deleted, the layout is restored without them and
+ Superset tells you how many were not reattached. Archived charts are not
+ skipped: they are linked to the dashboard as in the version, so restoring
+ one from the archive later puts it back on that dashboard.
Review Comment:
Added a sentence on the unlink direction in 1f54dced2b.
##########
superset/versioning/restore.py:
##########
@@ -742,11 +748,29 @@ def _restore_dashboard_membership(dashboard: Any,
transaction_id: int) -> list[i
if window.contains(transaction_id)
}
)
- if not member_ids:
- dashboard.slices = []
- return []
-
- live_slices =
db.session.query(Slice).filter(Slice.id.in_(member_ids)).all()
+ # Archived charts must be visible both to the lookup and to the
+ # assignment, which diffs against the current membership. A membership
+ # loaded through ``dashboard.slices`` misses archived members, even inside
+ # the bypass, because the dashboard's own load carried the filter, so the
+ # flush would keep or re-insert their rows. Read it from the association
+ # table instead and diff against that.
+ with skip_visibility_filter(db.session, Slice):
+ current_slices: list[Slice] = (
+ db.session.query(Slice)
+ .join(dashboard_slices, dashboard_slices.c.slice_id == Slice.id)
+ .filter(dashboard_slices.c.dashboard_id == dashboard.id)
+ .all()
+ )
+ live_slices: list[Slice] = (
+ db.session.query(Slice).filter(Slice.id.in_(member_ids)).all()
+ if member_ids
+ else []
+ )
Review Comment:
This race predates the PR (live members were read the same way), and if it
happens the restore fails and rolls back cleanly, so a retry works. Not
changing it here.
--
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]