Skip to content

Commit f5d489c

Browse files
committed
use tbl.history() instead of ancestors_of()
We don't need to find all the ancestors, we only need to validate that the snapshot is an ancestor, i.e if it was ever current.
1 parent 1af604a commit f5d489c

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

pyiceberg/table/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
SnapshotLogEntry,
114114
SnapshotSummaryCollector,
115115
Summary,
116-
ancestors_of,
117116
update_snapshot_summaries,
118117
)
119118
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
@@ -2020,10 +2019,7 @@ def rollback_to_snapshot(self, snapshot_id: int) -> ManageSnapshots:
20202019
self._commit_if_ref_updates_exist()
20212020
if self._transaction._table.snapshot_by_id(snapshot_id) is None:
20222021
raise ValidationError(f"Cannot roll back to unknown snapshot id: {snapshot_id}")
2023-
if snapshot_id not in {
2024-
ancestor.snapshot_id
2025-
for ancestor in ancestors_of(self._transaction._table.current_snapshot(), self._transaction.table_metadata)
2026-
}:
2022+
if snapshot_id not in {ancestor.snapshot_id for ancestor in self._transaction._table.history()}:
20272023
raise ValidationError(f"Cannot roll back to snapshot, not an ancestor of the current state: {snapshot_id}")
20282024

20292025
update, requirement = self._transaction._set_ref_snapshot(snapshot_id=snapshot_id, ref_name="main", type="branch")

0 commit comments

Comments
 (0)