From d99297797550f943bac729cd2f10940dbef8a48a Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Fri, 5 Jun 2026 13:20:23 +0900 Subject: [PATCH 1/2] Add defaults to ViewVersion fields --- pyiceberg/view/metadata.py | 7 ++++--- tests/catalog/test_rest.py | 6 ------ tests/integration/test_writes/test_writes.py | 3 --- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pyiceberg/view/metadata.py b/pyiceberg/view/metadata.py index 785dfd7852..ad319ca392 100644 --- a/pyiceberg/view/metadata.py +++ b/pyiceberg/view/metadata.py @@ -16,6 +16,7 @@ # under the License. from __future__ import annotations +import time from typing import Literal from pydantic import Field, RootModel, field_validator @@ -44,13 +45,13 @@ class ViewRepresentation(IcebergBaseModel, RootModel): class ViewVersion(IcebergBaseModel): """A version of the view definition.""" - version_id: int = Field(alias="version-id") + version_id: int = Field(alias="version-id", default=1) """ID for the version""" schema_id: int = Field(alias="schema-id") """ID of the schema for the view version""" - timestamp_ms: int = Field(alias="timestamp-ms") + timestamp_ms: int = Field(alias="timestamp-ms", default=int(time.time() * 1000)) """Timestamp when the version was created (ms from epoch)""" - summary: dict[str, str] = Field() + summary: dict[str, str] = Field(default={}) """A string to string map of summary metadata about the version""" representations: list[ViewRepresentation] = Field() """A list of representations for the view definition""" diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py index 1eb9f26a56..ce53755d71 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -1746,10 +1746,7 @@ def test_create_view_200(rest_mock: Mocker, table_schema_simple: Schema, example identifier=("fokko", "fokko2"), schema=table_schema_simple, view_version=ViewVersion( - version_id=1, - timestamp_ms=12345, schema_id=1, - summary={"engine-name": "spark", "engineVersion": "3.3"}, representations=[ { "type": "sql", @@ -1791,10 +1788,7 @@ def test_create_view_409( identifier=("fokko", "fokko2"), schema=table_schema_simple, view_version=ViewVersion( - version_id=1, - timestamp_ms=12345, schema_id=1, - summary={"engine-name": "spark", "engineVersion": "3.3"}, representations=[], default_namespace=[], ), diff --git a/tests/integration/test_writes/test_writes.py b/tests/integration/test_writes/test_writes.py index 609c1863bc..2a0c50a921 100644 --- a/tests/integration/test_writes/test_writes.py +++ b/tests/integration/test_writes/test_writes.py @@ -1769,10 +1769,7 @@ def test_create_view( identifier = "default.some_view" schema = pa.schema([pa.field("some_col", pa.int32())]) view_version = ViewVersion( - version_id=1, schema_id=1, - timestamp_ms=int(time.time() * 1000), - summary={}, representations=[ SQLViewRepresentation( type="sql", From dde397b9c07f75e7ba1de3e1d46b23f459d7578b Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Sat, 6 Jun 2026 20:01:29 +0900 Subject: [PATCH 2/2] fixup! Add defaults to ViewVersion fields --- pyiceberg/view/metadata.py | 4 ++-- tests/catalog/test_rest.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyiceberg/view/metadata.py b/pyiceberg/view/metadata.py index ad319ca392..33766040e3 100644 --- a/pyiceberg/view/metadata.py +++ b/pyiceberg/view/metadata.py @@ -49,9 +49,9 @@ class ViewVersion(IcebergBaseModel): """ID for the version""" schema_id: int = Field(alias="schema-id") """ID of the schema for the view version""" - timestamp_ms: int = Field(alias="timestamp-ms", default=int(time.time() * 1000)) + timestamp_ms: int = Field(alias="timestamp-ms", default_factory=lambda: int(time.time() * 1000)) """Timestamp when the version was created (ms from epoch)""" - summary: dict[str, str] = Field(default={}) + summary: dict[str, str] = Field(default_factory=dict) """A string to string map of summary metadata about the version""" representations: list[ViewRepresentation] = Field() """A list of representations for the view definition""" diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py index ce53755d71..691e163744 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -1747,6 +1747,7 @@ def test_create_view_200(rest_mock: Mocker, table_schema_simple: Schema, example schema=table_schema_simple, view_version=ViewVersion( schema_id=1, + summary={"engine-name": "spark", "engineVersion": "3.3"}, representations=[ { "type": "sql", @@ -1789,6 +1790,7 @@ def test_create_view_409( schema=table_schema_simple, view_version=ViewVersion( schema_id=1, + summary={"engine-name": "spark", "engineVersion": "3.3"}, representations=[], default_namespace=[], ),