6060 Snapshot ,
6161 SnapshotSummaryCollector ,
6262 Summary ,
63+ ancestors_of ,
6364 update_snapshot_summaries ,
6465)
6566from pyiceberg .table .update import (
@@ -254,9 +255,10 @@ def _commit(self) -> UpdatesAndRequirements:
254255 manifest_list_file_path = location_provider .new_metadata_location (file_name )
255256
256257 # get current snapshot id and starting snapshot id, and validate that there are no conflicts
257- starting_snapshot_id = self ._parent_snapshot_id
258- current_snapshot_id = self ._transaction ._table .refresh ().metadata .current_snapshot_id
259- self ._validate (starting_snapshot_id , current_snapshot_id )
258+ if self ._transaction ._table .__class__ .__name__ != "StagedTable" :
259+ starting_snapshot = self ._transaction .table_metadata .current_snapshot ()
260+ current_snapshot = self ._transaction ._table .refresh ().metadata .current_snapshot ()
261+ self ._validate (starting_snapshot , current_snapshot )
260262
261263 with write_manifest_list (
262264 format_version = self ._transaction .table_metadata .format_version ,
@@ -286,10 +288,7 @@ def _commit(self) -> UpdatesAndRequirements:
286288 (AssertRefSnapshotId (snapshot_id = self ._transaction .table_metadata .current_snapshot_id , ref = "main" ),),
287289 )
288290
289- def _validate (self , starting_snapshot_id : Optional [int ], current_snapshot_id : Optional [int ]) -> None :
290- # get all the snapshots between the current snapshot id and the parent id
291- snapshots = ancestors_between (starting_snapshot_id , current_snapshot_id , self ._transaction ._table .metadata .snapshot_by_id )
292-
291+ def _validate (self , starting_snapshot : Optional [Snapshot ], current_snapshot : Optional [Snapshot ]) -> None :
293292 # Define allowed operations for each type of operation
294293 allowed_operations = {
295294 Operation .APPEND : {Operation .APPEND , Operation .REPLACE , Operation .OVERWRITE , Operation .DELETE },
@@ -298,7 +297,13 @@ def _validate(self, starting_snapshot_id: Optional[int], current_snapshot_id: Op
298297 Operation .DELETE : set (),
299298 }
300299
300+ # get all the snapshots between the current snapshot id and the parent id
301+ snapshots = ancestors_of (current_snapshot , self ._transaction ._table .metadata )
302+
301303 for snapshot in snapshots :
304+ if snapshot .snapshot_id == starting_snapshot .snapshot_id :
305+ break
306+
302307 snapshot_operation = snapshot .summary .operation
303308
304309 if snapshot_operation not in allowed_operations [self ._operation ]:
0 commit comments