From 2463861eb7df25a62d89a1b8b6603d0fa9d39b7d Mon Sep 17 00:00:00 2001 From: Tom Ron Date: Mon, 30 Nov 2026 21:16:06 +0200 Subject: [PATCH 1/4] Skip remove-properties commits that change nothing Removing property keys that aren't set still recorded the update, so update_table_metadata bumped last_updated_ms and defeated the catalogs' skip-commit check: a repeated remove_properties, or one that loses a race to a concurrent removal, wrote a new metadata JSON, added a metadata-log entry and swapped the catalog pointer for a commit that changes nothing. Record the update only when at least one key was removed, the same way the set-properties and upgrade-format-version handlers return early. Closes #4538 --- pyiceberg/table/update/__init__.py | 9 ++++++++- tests/catalog/test_catalog_behaviors.py | 17 +++++++++++++++++ tests/catalog/test_glue.py | 25 +++++++++++++++++++++++++ tests/integration/test_catalog.py | 16 ++++++++++++++++ tests/table/test_init.py | 5 +++-- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/pyiceberg/table/update/__init__.py b/pyiceberg/table/update/__init__.py index 67a4e1fba6..89da2ff0b4 100644 --- a/pyiceberg/table/update/__init__.py +++ b/pyiceberg/table/update/__init__.py @@ -377,9 +377,16 @@ def _(update: RemovePropertiesUpdate, base_metadata: TableMetadata, context: _Ta return base_metadata properties = dict(base_metadata.properties) + removed = False for key in update.removals: # Ignore keys that aren't set, since a concurrent commit may have removed them - properties.pop(key, None) + removed |= properties.pop(key, None) is not None + + if not removed: + # Nothing was removed, so there is no change to record. Recording the update anyway + # would bump last_updated_ms and defeat the catalogs' skip-commit check, writing a + # new metadata version that changes nothing. + return base_metadata context.add_update(update) return base_metadata.model_copy(update={"properties": properties}) diff --git a/tests/catalog/test_catalog_behaviors.py b/tests/catalog/test_catalog_behaviors.py index 4e51a4dbda..80790fe1f2 100644 --- a/tests/catalog/test_catalog_behaviors.py +++ b/tests/catalog/test_catalog_behaviors.py @@ -778,6 +778,23 @@ def test_remove_properties_already_removed_by_concurrent_commit( assert catalog.load_table(test_table_identifier).properties == {} +def test_remove_unset_properties_writes_no_new_metadata( + catalog: Catalog, table_schema_simple: Schema, test_table_identifier: Identifier +) -> None: + namespace = Catalog.namespace_from(test_table_identifier) + catalog.create_namespace(namespace) + table = catalog.create_table(test_table_identifier, table_schema_simple, properties={"a": "1"}) + + metadata_location = table.metadata_location + table.transaction().remove_properties("missing", "also-missing").commit_transaction() + + loaded = catalog.load_table(test_table_identifier) + assert loaded.properties == {"a": "1"} + # Nothing was removed, so the staged metadata equals the current metadata and the + # catalog must skip the commit instead of writing a metadata version that changes nothing + assert loaded.metadata_location == metadata_location + + # Append table diff --git a/tests/catalog/test_glue.py b/tests/catalog/test_glue.py index 5f1ecab2c7..1980f2e028 100644 --- a/tests/catalog/test_glue.py +++ b/tests/catalog/test_glue.py @@ -133,6 +133,31 @@ def test_create_table_with_database_location( assert storage_descriptor["Location"] == f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}" +@mock_aws +def test_remove_unset_properties_writes_no_new_metadata( + _glue: boto3.client, + _bucket_initialize: None, + moto_endpoint_url: str, + table_schema_nested: Schema, + database_name: str, + table_name: str, +) -> None: + catalog_name = "glue" + identifier = (database_name, table_name) + test_catalog = GlueCatalog(catalog_name, client=None, **{"s3.endpoint": moto_endpoint_url}) + test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"}) + table = test_catalog.create_table(identifier, table_schema_nested, properties={"a": "1"}) + + metadata_location = table.metadata_location + table.transaction().remove_properties("missing").commit_transaction() + + loaded = test_catalog.load_table(identifier) + assert loaded.properties["a"] == "1" + # Nothing was removed, so the staged metadata equals the current metadata and the + # catalog must skip the commit instead of writing a metadata version that changes nothing + assert loaded.metadata_location == metadata_location + + @mock_aws def test_create_v1_table( _bucket_initialize: None, diff --git a/tests/integration/test_catalog.py b/tests/integration/test_catalog.py index ab9589cb85..4e7f82fb16 100644 --- a/tests/integration/test_catalog.py +++ b/tests/integration/test_catalog.py @@ -583,6 +583,22 @@ def test_update_table_spec_then_revert(test_catalog: Catalog, test_schema: Schem assert table.spec() == initial_spec +@pytest.mark.integration +@pytest.mark.parametrize("test_catalog", CATALOGS) +def test_remove_properties_already_removed_by_concurrent_commit( + test_catalog: Catalog, test_schema: Schema, table_name: str, database_name: str +) -> None: + identifier = (database_name, table_name) + test_catalog.create_namespace(database_name) + table = test_catalog.create_table(identifier, test_schema, properties={"a": "1", "b": "2"}) + + transaction = table.transaction().remove_properties("a", "b") + test_catalog.load_table(identifier).transaction().remove_properties("a").commit_transaction() + transaction.commit_transaction() + + assert test_catalog.load_table(identifier).properties == {} + + @pytest.mark.integration @pytest.mark.parametrize("test_catalog", CATALOGS) def test_register_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None: diff --git a/tests/table/test_init.py b/tests/table/test_init.py index f6e0bab93a..30421cc365 100644 --- a/tests/table/test_init.py +++ b/tests/table/test_init.py @@ -1287,8 +1287,9 @@ def test_apply_remove_properties_update_ignores_unset_keys(table_v2: Table) -> N new_metadata_no_removal = update_table_metadata(base_metadata, (RemovePropertiesUpdate(removals=["test_a"]),)) - assert new_metadata_no_removal.properties == base_metadata.properties - assert new_metadata_no_removal.last_updated_ms > base_metadata.last_updated_ms + # Removing only unset keys is a no-op: nothing is recorded, so last_updated_ms is not bumped + # and the catalogs' skip-commit check still recognizes the metadata as unchanged + assert new_metadata_no_removal == base_metadata new_metadata = update_table_metadata(base_metadata, (RemovePropertiesUpdate(removals=["read.split.target.size", "test_a"]),)) From 1d1161ed8f05bb27f49a2e073f1f0036c4dcdc0b Mon Sep 17 00:00:00 2001 From: Tom Ron Date: Thu, 3 Dec 2026 17:14:02 +0200 Subject: [PATCH 2/4] Fix remove-properties integration test for catalogs with default properties REST catalogs add default table properties such as write.parquet.compression-codec, so asserting an empty property map fails. Assert only that the removed keys are gone. --- tests/integration/test_catalog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_catalog.py b/tests/integration/test_catalog.py index 4e7f82fb16..3093c564bc 100644 --- a/tests/integration/test_catalog.py +++ b/tests/integration/test_catalog.py @@ -596,7 +596,8 @@ def test_remove_properties_already_removed_by_concurrent_commit( test_catalog.load_table(identifier).transaction().remove_properties("a").commit_transaction() transaction.commit_transaction() - assert test_catalog.load_table(identifier).properties == {} + properties = test_catalog.load_table(identifier).properties + assert "a" not in properties and "b" not in properties @pytest.mark.integration From d84e23c614498d53ebea7b438fe9d5f999fdee23 Mon Sep 17 00:00:00 2001 From: Tom Ron Date: Thu, 3 Dec 2026 22:18:43 +0200 Subject: [PATCH 3/4] Retrigger CI The windows-unit-test (3.12) job failed on test_cache_expires_entries, a timing-dependent test unrelated to this change (see #4602). From 466eb0ff8cda8062bb36b1d40665766da49ac804 Mon Sep 17 00:00:00 2001 From: Tom Ron Date: Fri, 4 Dec 2026 08:59:58 +0200 Subject: [PATCH 4/4] Cover empty-string removal and no-op concurrent removal in tests Add a case for removing a property whose value is an empty string, so the `is not None` check is pinned. Make the concurrent-removal integration test assert the metadata location is unchanged when the concurrent commit already removed every key (skipped for REST, where the server decides). --- tests/integration/test_catalog.py | 11 ++++++++--- tests/table/test_init.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_catalog.py b/tests/integration/test_catalog.py index 3093c564bc..43fe13e205 100644 --- a/tests/integration/test_catalog.py +++ b/tests/integration/test_catalog.py @@ -593,11 +593,16 @@ def test_remove_properties_already_removed_by_concurrent_commit( table = test_catalog.create_table(identifier, test_schema, properties={"a": "1", "b": "2"}) transaction = table.transaction().remove_properties("a", "b") - test_catalog.load_table(identifier).transaction().remove_properties("a").commit_transaction() + test_catalog.load_table(identifier).transaction().remove_properties("a", "b").commit_transaction() + metadata_location = test_catalog.load_table(identifier).metadata_location transaction.commit_transaction() - properties = test_catalog.load_table(identifier).properties - assert "a" not in properties and "b" not in properties + loaded = test_catalog.load_table(identifier) + assert "a" not in loaded.properties and "b" not in loaded.properties + if not isinstance(test_catalog, RestCatalog): + # Every key was already removed, so the staged metadata equals the current metadata and the + # catalog must skip the commit. A REST server decides this itself and may still write a version. + assert loaded.metadata_location == metadata_location @pytest.mark.integration diff --git a/tests/table/test_init.py b/tests/table/test_init.py index 30421cc365..8a0b2ce697 100644 --- a/tests/table/test_init.py +++ b/tests/table/test_init.py @@ -1298,6 +1298,17 @@ def test_apply_remove_properties_update_ignores_unset_keys(table_v2: Table) -> N assert new_metadata.last_updated_ms > base_metadata.last_updated_ms +def test_apply_remove_properties_update_removes_empty_string_value(table_v2: Table) -> None: + base_metadata = update_table_metadata(table_v2.metadata, (SetPropertiesUpdate(updates={"empty": ""}),)) + assert base_metadata.properties["empty"] == "" + + new_metadata = update_table_metadata(base_metadata, (RemovePropertiesUpdate(removals=["empty"]),)) + + # A property set to an empty string is still a set property, so removing it is a real change + assert "empty" not in new_metadata.properties + assert new_metadata != base_metadata + + def test_apply_add_schema_update(table_v2: Table) -> None: transaction = table_v2.transaction() update = transaction.update_schema()