Skip to content

Commit 82e65e1

Browse files
committed
Fixed comments for AssertSnapshotRef
1 parent bc6fb68 commit 82e65e1

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

pyiceberg/table/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ def _set_ref_snapshot(
341341
AssertRefSnapshotId(
342342
snapshot_id=self.table_metadata.refs[ref_name].snapshot_id if ref_name in self.table_metadata.refs else None,
343343
ref=ref_name,
344-
ref_type=type,
345344
),
346345
)
347346

pyiceberg/table/update/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,16 @@ class AssertRefSnapshotId(ValidatableTableRequirement):
609609

610610
type: Literal["assert-ref-snapshot-id"] = Field(default="assert-ref-snapshot-id")
611611
ref: str = Field(...)
612-
ref_type: SnapshotRefType = Field(...)
612+
# ref_type: SnapshotRefType = Field(...)
613613
snapshot_id: Optional[int] = Field(default=None, alias="snapshot-id")
614614

615615
def validate(self, base_metadata: Optional[TableMetadata]) -> None:
616616
if base_metadata is None:
617617
raise CommitFailedException("Requirement failed: current table metadata is missing")
618618
elif len(base_metadata.snapshots) == 0 and self.ref != MAIN_BRANCH:
619-
raise CommitFailedException(f"Requirement failed: No snapshot available in table for ref: {self.ref}")
619+
raise CommitFailedException(
620+
f"Requirement failed: Table has no snapshots and can only be written to the {MAIN_BRANCH} BRANCH."
621+
)
620622
elif snapshot_ref := base_metadata.refs.get(self.ref):
621623
ref_type = snapshot_ref.snapshot_ref_type
622624
if self.snapshot_id is None:
@@ -625,8 +627,8 @@ def validate(self, base_metadata: Optional[TableMetadata]) -> None:
625627
raise CommitFailedException(
626628
f"Requirement failed: {ref_type} {self.ref} has changed: expected id {self.snapshot_id}, found {snapshot_ref.snapshot_id}"
627629
)
628-
elif ref_type != self.ref_type:
629-
raise CommitFailedException(f"Requirement failed: {ref_type} {self.ref} can't be changed to type {self.ref_type}")
630+
elif ref_type == SnapshotRefType.TAG:
631+
raise CommitFailedException(f"Requirement failed: TAG {self.ref} can't be updated once created")
630632
elif self.snapshot_id is not None:
631633
raise CommitFailedException(f"Requirement failed: branch or tag {self.ref} is missing, expected {self.snapshot_id}")
632634

pyiceberg/table/update/snapshot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ def _commit(self) -> UpdatesAndRequirements:
287287
if self._branch in self._transaction.table_metadata.refs
288288
else self._transaction.table_metadata.current_snapshot_id,
289289
ref=self._branch,
290-
ref_type=SnapshotRefType.BRANCH,
291290
),
292291
),
293292
)

tests/integration/test_writes/test_writes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from pyiceberg.io.pyarrow import _dataframe_to_data_files
4545
from pyiceberg.partitioning import PartitionField, PartitionSpec
4646
from pyiceberg.schema import Schema
47-
from pyiceberg.table import TableProperties
47+
from pyiceberg.table import TableProperties, MAIN_BRANCH
4848
from pyiceberg.table.sorting import SortDirection, SortField, SortOrder
4949
from pyiceberg.transforms import DayTransform, HourTransform, IdentityTransform
5050
from pyiceberg.types import (
@@ -1578,7 +1578,7 @@ def test_abort_table_transaction_on_exception(
15781578
def test_append_to_non_existing_branch(session_catalog: Catalog, arrow_table_with_null: pa.Table) -> None:
15791579
identifier = "default.test_non_existing_branch"
15801580
tbl = _create_table(session_catalog, identifier, {"format-version": "2"}, [])
1581-
with pytest.raises(CommitFailedException, match="No snapshot available in table for ref:"):
1581+
with pytest.raises(CommitFailedException, match=f"Table has no snapshots and can only be written to the {MAIN_BRANCH} BRANCH."):
15821582
tbl.append(arrow_table_with_null, branch="non_existing_branch")
15831583

15841584

tests/table/test_init.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
_match_deletes_to_data_file,
5050
)
5151
from pyiceberg.table.metadata import INITIAL_SEQUENCE_NUMBER, TableMetadataUtil, TableMetadataV2, _generate_snapshot_id
52-
from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
52+
from pyiceberg.table.refs import SnapshotRef
5353
from pyiceberg.table.snapshots import (
5454
MetadataLogEntry,
5555
Operation,
@@ -982,43 +982,41 @@ def test_assert_table_uuid(table_v2: Table) -> None:
982982

983983
def test_assert_ref_snapshot_id(table_v2: Table) -> None:
984984
base_metadata = table_v2.metadata
985-
AssertRefSnapshotId(ref="main", snapshot_id=base_metadata.current_snapshot_id, ref_type=SnapshotRefType.BRANCH).validate(
986-
base_metadata
987-
)
985+
AssertRefSnapshotId(ref="main", snapshot_id=base_metadata.current_snapshot_id).validate(base_metadata)
988986

989987
with pytest.raises(CommitFailedException, match="Requirement failed: current table metadata is missing"):
990-
AssertRefSnapshotId(ref="main", snapshot_id=1, ref_type=SnapshotRefType.BRANCH).validate(None)
988+
AssertRefSnapshotId(ref="main", snapshot_id=1).validate(None)
991989

992990
with pytest.raises(
993991
CommitFailedException,
994992
match="Requirement failed: branch main was created concurrently",
995993
):
996-
AssertRefSnapshotId(ref="main", snapshot_id=None, ref_type=SnapshotRefType.BRANCH).validate(base_metadata)
994+
AssertRefSnapshotId(ref="main", snapshot_id=None).validate(base_metadata)
997995

998996
with pytest.raises(
999997
CommitFailedException,
1000998
match="Requirement failed: branch main has changed: expected id 1, found 3055729675574597004",
1001999
):
1002-
AssertRefSnapshotId(ref="main", snapshot_id=1, ref_type=SnapshotRefType.BRANCH).validate(base_metadata)
1000+
AssertRefSnapshotId(ref="main", snapshot_id=1).validate(base_metadata)
10031001

10041002
with pytest.raises(
10051003
CommitFailedException,
10061004
match="Requirement failed: branch or tag not_exist_branch is missing, expected 1",
10071005
):
1008-
AssertRefSnapshotId(ref="not_exist_branch", snapshot_id=1, ref_type=SnapshotRefType.BRANCH).validate(base_metadata)
1006+
AssertRefSnapshotId(ref="not_exist_branch", snapshot_id=1).validate(base_metadata)
10091007

10101008
with pytest.raises(
10111009
CommitFailedException,
10121010
match="Requirement failed: branch or tag not_exist_tag is missing, expected 1",
10131011
):
1014-
AssertRefSnapshotId(ref="not_exist_tag", snapshot_id=1, ref_type=SnapshotRefType.TAG).validate(base_metadata)
1012+
AssertRefSnapshotId(ref="not_exist_tag", snapshot_id=1).validate(base_metadata)
10151013

10161014
# existing Tag in metadata: test
10171015
with pytest.raises(
10181016
CommitFailedException,
1019-
match="Requirement failed: tag test can't be changed to type branch",
1017+
match="Requirement failed: TAG test can't be updated once created",
10201018
):
1021-
AssertRefSnapshotId(ref="test", snapshot_id=3051729675574597004, ref_type=SnapshotRefType.BRANCH).validate(base_metadata)
1019+
AssertRefSnapshotId(ref="test", snapshot_id=3051729675574597004).validate(base_metadata)
10221020

10231021

10241022
def test_assert_last_assigned_field_id(table_v2: Table) -> None:

0 commit comments

Comments
 (0)