diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 057dd8427c..8953b69866 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -504,6 +504,9 @@ def _(update: AddSchemaUpdate, base_metadata: TableMetadata, context: _TableMeta if update.last_column_id < base_metadata.last_column_id: raise ValueError(f"Invalid last column id {update.last_column_id}, must be >= {base_metadata.last_column_id}") + # PROBLEM: `update.schema_`'s `schema_id` starts with 0 but should be 1 + # fresh_schema = assign_fresh_schema_ids(update.schema_) + context.add_update(update) return base_metadata.model_copy( update={ diff --git a/tests/catalog/test_base.py b/tests/catalog/test_base.py index cbe6322d02..9fb218350f 100644 --- a/tests/catalog/test_base.py +++ b/tests/catalog/test_base.py @@ -371,6 +371,11 @@ def test_commit_table(catalog: InMemoryCatalog) -> None: NestedField(4, "add", LongType()), ) + assert given_table.metadata.current_schema_id == 0 + assert len(given_table.metadata.schemas) == 1 + assert given_table.metadata.schemas[0] == TEST_TABLE_SCHEMA + assert given_table.metadata.last_column_id == TEST_TABLE_SCHEMA.highest_field_id + # When response = given_table.catalog._commit_table( # pylint: disable=W0212 CommitTableRequest( @@ -384,7 +389,7 @@ def test_commit_table(catalog: InMemoryCatalog) -> None: # Then assert response.metadata.table_uuid == given_table.metadata.table_uuid - # assert len(response.metadata.schemas) == 1 + assert len(response.metadata.schemas) == 1 # assert response.metadata.schemas[0] == new_schema