Skip to content

Commit 616a90d

Browse files
Check format version compatibility in UpdateSchema._commit
1 parent 24d26f7 commit 616a90d

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎pyiceberg/table/update/schema.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def _commit(self) -> UpdatesAndRequirements:
633633

634634
# Check if it is different current schema ID
635635
if existing_schema_id != self._schema.schema_id:
636+
new_schema.check_format_version_compatibility(self._transaction.table_metadata.format_version)
636637
requirements += (AssertCurrentSchemaId(current_schema_id=self._schema.schema_id),)
637638
if existing_schema_id is None:
638639
updates += (

‎tests/catalog/test_catalog_behaviors.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,22 @@ def test_update_schema_rejects_v3_only_types(catalog: Catalog, format_version: i
13491349
assert catalog.load_table(identifier).schema() == Schema(NestedField(1, "id", LongType(), required=False))
13501350

13511351

1352+
@pytest.mark.parametrize("format_version", [1, 2])
1353+
def test_update_schema_commit_checks_format_version(catalog: Catalog, format_version: int) -> None:
1354+
catalog.create_namespace("default")
1355+
identifier = f"default.commit_checks_format_version_v{format_version}_{catalog.name}"
1356+
tbl = catalog.create_table(
1357+
identifier=identifier,
1358+
schema=Schema(NestedField(1, "id", LongType(), required=False)),
1359+
properties={"format-version": str(format_version)},
1360+
)
1361+
1362+
# The check runs while building the updates, before they reach the table metadata
1363+
update = tbl.update_schema().add_column("ts", TimestampNanoType())
1364+
with pytest.raises(ValueError, match="timestamp_ns is only supported in 3 or higher"):
1365+
update._commit()
1366+
1367+
13521368
@pytest.mark.parametrize("format_version", [1, 2])
13531369
def test_update_schema_rejects_initial_default_before_v3(catalog: Catalog, format_version: int) -> None:
13541370
catalog.create_namespace("default")

0 commit comments

Comments
 (0)