Skip to content

Commit e272b26

Browse files
committed
fix bug in ancestors_between
1 parent c16a3e6 commit e272b26

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

pyiceberg/table/snapshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ def ancestors_between(
443443
"""Get the ancestors of and including the given snapshot between the to and from snapshots."""
444444
if from_snapshot is not None:
445445
for snapshot in ancestors_of(to_snapshot, table_metadata):
446+
yield snapshot
446447
if snapshot == from_snapshot:
447448
break
448-
yield snapshot
449449
else:
450450
yield from ancestors_of(to_snapshot, table_metadata)

tests/table/test_snapshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,5 +397,5 @@ def test_ancestors_between(table_v2_with_extensive_snapshots: Table) -> None:
397397
)
398398
)
399399
)
400-
== 1999
400+
== 2000
401401
)

tests/table/test_validate.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
from pyiceberg.table.update.validate import validation_history
2929

3030

31-
def test_validation_history(table_v2_with_extensive_snapshots: Table) -> None:
32-
"""Test the validation history function."""
31+
@pytest.fixture
32+
def table_v2_with_extensive_snapshots_and_manifests(
33+
table_v2_with_extensive_snapshots: Table,
34+
) -> tuple[Table, dict[int, list[ManifestFile]]]:
35+
"""Fixture to create a table with extensive snapshots and manifests."""
3336
mock_manifests = {}
3437

3538
for i, snapshot in enumerate(table_v2_with_extensive_snapshots.snapshots()):
@@ -46,10 +49,17 @@ def test_validation_history(table_v2_with_extensive_snapshots: Table) -> None:
4649
# Store the manifest for this specific snapshot
4750
mock_manifests[snapshot.snapshot_id] = [mock_manifest]
4851

49-
expected_manifest_data_counts = len([m for m in mock_manifests.values() if m[0].content == ManifestContent.DATA]) - 1
52+
return table_v2_with_extensive_snapshots, mock_manifests
53+
54+
55+
def test_validation_history(table_v2_with_extensive_snapshots_and_manifests: tuple[Table, dict[int, list[ManifestFile]]]) -> None:
56+
"""Test the validation history function."""
57+
table, mock_manifests = table_v2_with_extensive_snapshots_and_manifests
58+
59+
expected_manifest_data_counts = len([m for m in mock_manifests.values() if m[0].content == ManifestContent.DATA])
5060

51-
oldest_snapshot = table_v2_with_extensive_snapshots.snapshots()[0]
52-
newest_snapshot = cast(Snapshot, table_v2_with_extensive_snapshots.current_snapshot())
61+
oldest_snapshot = table.snapshots()[0]
62+
newest_snapshot = cast(Snapshot, table.current_snapshot())
5363

5464
def mock_read_manifest_side_effect(self: Snapshot, io: FileIO) -> list[ManifestFile]:
5565
"""Mock the manifests method to use the snapshot_id for lookup."""
@@ -60,7 +70,7 @@ def mock_read_manifest_side_effect(self: Snapshot, io: FileIO) -> list[ManifestF
6070

6171
with patch("pyiceberg.table.snapshots.Snapshot.manifests", new=mock_read_manifest_side_effect):
6272
manifests, snapshots = validation_history(
63-
table_v2_with_extensive_snapshots,
73+
table,
6474
newest_snapshot,
6575
oldest_snapshot,
6676
{Operation.APPEND},
@@ -80,7 +90,7 @@ def mock_read_manifest_side_effect(self: Snapshot, io: FileIO) -> list[ManifestF
8090
with patch("pyiceberg.table.update.validate.ancestors_between", return_value=[snapshot_with_no_summary]):
8191
with pytest.raises(ValidationException):
8292
validation_history(
83-
table_v2_with_extensive_snapshots,
93+
table,
8494
newest_snapshot,
8595
oldest_snapshot,
8696
{Operation.APPEND},

0 commit comments

Comments
 (0)