This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new 8fe63dc74 fix: add Field alias for SetPartitionStatisticsUpdate (#3035)
8fe63dc74 is described below
commit 8fe63dc74be77266ed8b899449fc25029eab797b
Author: shiwk <[email protected]>
AuthorDate: Thu Feb 19 04:19:22 2026 +0800
fix: add Field alias for SetPartitionStatisticsUpdate (#3035)
<!--
Thanks for opening a pull request!
-->
<!-- In the case this PR will resolve an issue, please replace
${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
<!-- Closes #${GITHUB_ISSUE_ID} -->
# Rationale for this change
Add `Field(alias="partition-statistics")` to
`SetPartitionStatisticsUpdate.partition_statistics` to ensure correct
serialization/deserialization with the hyphenated key format.
## Problem
The `partition_statistics` field was missing an explicit `Field` alias,
which means:
- When serializing with `model_dump(by_alias=True)`, it would use the
Python attribute name `partition_statistics` (with underscore) instead
of the Iceberg specification format `partition-statistics` (with hyphen)
- This causes incompatibility with the Iceberg table metadata format
specification
## Solution
Added `Field(alias="partition-statistics")` to ensure:
- Proper serialization to JSON/dict using hyphenated key names that
comply with Iceberg spec
- Correct deserialization when parsing external metadata with hyphenated
keys
- Consistency with other similar fields in the codebase (e.g.,
`snapshot_ids` with alias `snapshot-ids`)
## Are these changes tested?
Yes. Added verification in `test_set_partition_statistics_update()` to
validate that:
1. The update object serializes to JSON with the correct
`"partition-statistics"` key
2. The key is present in the serialized output
## Are there any user-facing changes?
No. This is an internal fix to ensure metadata serialization format
compliance. The change is transparent to users and improves
interoperability with the Iceberg specification.
<!-- In the case of user-facing changes, please add the changelog label.
-->
---
pyiceberg/table/update/__init__.py | 2 +-
tests/table/test_init.py | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/pyiceberg/table/update/__init__.py
b/pyiceberg/table/update/__init__.py
index 455b46953..e892b838c 100644
--- a/pyiceberg/table/update/__init__.py
+++ b/pyiceberg/table/update/__init__.py
@@ -212,7 +212,7 @@ class RemoveSchemasUpdate(IcebergBaseModel):
class SetPartitionStatisticsUpdate(IcebergBaseModel):
action: Literal["set-partition-statistics"] =
Field(default="set-partition-statistics")
- partition_statistics: PartitionStatisticsFile
+ partition_statistics: PartitionStatisticsFile =
Field(alias="partition-statistics")
class RemovePartitionStatisticsUpdate(IcebergBaseModel):
diff --git a/tests/table/test_init.py b/tests/table/test_init.py
index aef6e3cc5..30c4a3a45 100644
--- a/tests/table/test_init.py
+++ b/tests/table/test_init.py
@@ -1605,6 +1605,10 @@ def
test_set_partition_statistics_update(table_v2_with_statistics: Table) -> Non
partition_statistics=partition_statistics_file,
)
+ # Verify that serialization uses 'partition-statistics' alias
+ dumped_with_alias = update.model_dump(by_alias=True)
+ assert "partition-statistics" in dumped_with_alias
+
new_metadata = update_table_metadata(
table_v2_with_statistics.metadata,
(update,),