Skip to content

Ignore unset keys when removing table properties - #4522

Merged
Fokko merged 2 commits into
apache:mainfrom
smaheshwar-pltr:sm/remove-missing-property
Nov 30, 2026
Merged

Fokko merged 2 commits into
apache:mainfrom
smaheshwar-pltr:sm/remove-missing-property

Conversation

@smaheshwar-pltr

@smaheshwar-pltr smaheshwar-pltr commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

With the SQL, in-memory, Hive and Glue catalogs, PyIceberg applies a commit's changes to the table's latest metadata itself, rather than a REST server doing it. Removing a property deletes each key, so the commit fails if another writer removed the same property first:

txn = tbl.transaction().remove_properties("owner")
catalog.load_table("default.t").transaction().remove_properties("owner").commit_transaction()
txn.commit_transaction()  # KeyError: 'owner'

The property is gone either way, so this skips keys that aren't set, as REST catalogs and the other implementations do (Java, Rust, Go, C++).

Are these changes tested?

Yes. A catalog test covers the concurrent removal, and a unit test covers unset keys. A Hive integration test expected KeyError when removing a Hive Metastore parameter that Iceberg doesn't see; it now checks that the removal leaves the parameter in place.

Are there any user-facing changes?

Removing a property that isn't set no longer raises KeyError, including a key that was never set, as with a REST catalog.

AI Disclosure: This PR was authored by Claude Code (Opus 5.5) but directed and overseen by me.

Applying a property removal popped each key, so the commit failed with a
KeyError if another writer had already removed the property. Skip keys
that aren't set, as the REST catalog does, and treat a removal of only
unset keys as a no-op.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread pyiceberg/table/update/__init__.py Resolved
Comment thread pyiceberg/table/update/__init__.py Resolved
@smaheshwar-pltr
smaheshwar-pltr marked this pull request as ready for review November 29, 2026 23:24

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! Tolerating unset keys matches Java's TableMetadata.Builder.removeProperties. One thing to align: the builder still records the RemoveProperties change when none of the keys are set (it only short-circuits on an empty set), so build() produces new metadata and the REST server (CatalogHandlers.commit) writes a new metadata file. _apply_table_update is the equivalent of MetadataUpdate.applyTo(Builder), and the SetPropertiesUpdate handler above already follows the builder this way. Suggestions inline. The Hive integration test still passes with them, since HiveCatalog.commit_table diffs the old and new Iceberg properties to decide what to remove from HMS.

Comment thread pyiceberg/table/update/__init__.py Resolved
Comment thread tests/table/test_init.py Resolved
As Java's TableMetadata.Builder.removeProperties does, only an empty
removal is skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @smaheshwar-pltr! Nice catch aligning with the Java/Rust/Go behavior, and good test coverage for the concurrent-removal case. 🚀

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @smaheshwar-pltr for fixing this, and for checking the Java, Rust, Go and C++ implementations! I've opened #4538 to follow up on a removal that changes nothing still writing a new metadata version.

@Fokko
Fokko added this pull request to the merge queue Nov 30, 2026
Merged via the queue into apache:main with commit 2df97e8 Nov 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants