Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,8 @@ def _plan_files_local(self) -> Iterable[FileScanTask]:
"""Plan files locally by reading manifests."""
snapshot = self.snapshot()
if not snapshot:
if self.snapshot_id is not None:
raise ValueError(f"Snapshot not found: {self.snapshot_id}")
return []
return self._manifest_planner.plan_files(snapshot.manifests(self.io))

Expand Down
11 changes: 11 additions & 0 deletions tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ def test_table_scan_missing_snapshot_zero(table_v2: Table) -> None:
assert table_v2.scan(snapshot_id=0).snapshot() is None


def test_table_scan_plan_files_missing_snapshot(table_v2: Table) -> None:
# table_v2 has no snapshot with id 0, so planning raises the same error as projection() and to_arrow()
scan = table_v2.scan(snapshot_id=0)

with pytest.raises(ValueError, match="Snapshot not found: 0"):
scan.plan_files()

with pytest.raises(ValueError, match="Snapshot not found: 0"):
scan.count()


@pytest.mark.parametrize("snapshot_id", [0, 3051729675574597004])
def test_table_scan_ref_cannot_override_snapshot(table_v2: Table, snapshot_id: int) -> None:
with pytest.raises(ValueError, match=f"Cannot override ref, already set snapshot id={snapshot_id}"):
Expand Down
Loading