@@ -105,6 +105,7 @@ class _SnapshotProducer(UpdateTableMetadata[U], Generic[U]):
105105 _added_data_files : List [DataFile ]
106106 _manifest_num_counter : itertools .count [int ]
107107 _deleted_data_files : Set [DataFile ]
108+ _target_branch = MAIN_BRANCH
108109
109110 def __init__ (
110111 self ,
@@ -124,20 +125,20 @@ def __init__(
124125 self ._deleted_data_files = set ()
125126 self .snapshot_properties = snapshot_properties
126127 self ._manifest_num_counter = itertools .count (0 )
127- self ._set_target_branch (branch = branch )
128+ self ._target_branch = self . _validate_target_branch (branch = branch )
128129 self ._parent_snapshot_id = (
129130 snapshot .snapshot_id if (snapshot := self ._transaction .table_metadata .snapshot_by_name (self ._target_branch )) else None
130131 )
131132
132- def _set_target_branch (self , branch : str ) -> None :
133+ def _validate_target_branch (self , branch : str ) -> str :
133134 # Default is already set to MAIN_BRANCH. So branch name can't be None.
134- assert branch is not None , "Invalid branch name: null"
135+ if branch is None :
136+ raise ValueError ("Invalid branch name: null" )
135137 if branch in self ._transaction .table_metadata .refs :
136138 ref = self ._transaction .table_metadata .refs [branch ]
137- assert (
138- ref .snapshot_ref_type == SnapshotRefType .BRANCH
139- ), f"{ branch } is a tag, not a branch. Tags cannot be targets for producing snapshots"
140- self ._target_branch = branch
139+ if ref .snapshot_ref_type != SnapshotRefType .BRANCH :
140+ raise ValueError (f"{ branch } is a tag, not a branch. Tags cannot be targets for producing snapshots" )
141+ return branch
141142
142143 def append_data_file (self , data_file : DataFile ) -> _SnapshotProducer [U ]:
143144 self ._added_data_files .append (data_file )
@@ -639,13 +640,13 @@ def __init__(
639640 self ,
640641 transaction : Transaction ,
641642 io : FileIO ,
643+ branch : str ,
642644 snapshot_properties : Dict [str , str ] = EMPTY_DICT ,
643- branch : Optional [str ] = MAIN_BRANCH ,
644645 ) -> None :
645646 self ._transaction = transaction
646647 self ._io = io
647648 self ._snapshot_properties = snapshot_properties
648- self ._branch = branch if branch is not None else MAIN_BRANCH
649+ self ._branch = branch
649650
650651 def fast_append (self ) -> _FastAppendFiles :
651652 return _FastAppendFiles (
0 commit comments