Skip to content

Commit f09cd2c

Browse files
committed
Make View.version return None for unknown version
1 parent 5da8186 commit f09cd2c

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

pyiceberg/view/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def versions(self) -> list[ViewVersion]:
5959
"""Get the versions of this view."""
6060
return self.metadata.versions
6161

62-
def version(self, version_id: int) -> ViewVersion:
63-
"""Get the version in this view by ID."""
64-
return next(version for version in self.metadata.versions if version.version_id == version_id)
62+
def version(self, version_id: int) -> ViewVersion | None:
63+
"""Get the version in this view by ID, or None if the ID cannot be found."""
64+
return next((version for version in self.metadata.versions if version.version_id == version_id), None)
6565

6666
def history(self) -> list[ViewHistoryEntry]:
6767
"""Get the version of this history view."""

tests/test_view.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def test_view_versions_multiple(example_view_metadata_v1_multiple_versions: dict
119119

120120

121121
def test_view_version_unknown_id(view: View) -> None:
122-
with pytest.raises(StopIteration):
123-
view.version(999)
122+
assert not view.version(999)
124123

125124

126125
def test_view_sql_for_unknown_dialect(view: View) -> None:

0 commit comments

Comments
 (0)