You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by fo...@apache.org on 2025/04/17 12:40:35 UTC
(iceberg-python) 08/11: Fix creation of Bucket Transforms with `pydantic>=2.11.0` (#1881)
This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch pyiceberg-0.9.x
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
commit e9745d5f63f4841ba725ca76343a8e3ac5574e6b
Author: b-rick <92...@users.noreply.github.com>
AuthorDate: Fri Apr 4 17:44:28 2025 +1100
Fix creation of Bucket Transforms with `pydantic>=2.11.0` (#1881)
## Rationale For This Change
When using pydantic>=2.11.0, we get an error when creating bucket
transforms. In this version, it's illegal to access self before calling
super. To fix this, we just need to ensure we call `super().__init__`
before setting field properties on `self`.
---
## Before
Using `pydantic==2.11.0` the test
`test_transforms.py::test_bucket_hash_values` fails
```python
tests/test_transforms.py:None (tests/test_transforms.py)
test_transforms.py:179: in <module>
(BucketTransform(2).transform(IntegerType()), 0, 0),
../pyiceberg/transforms.py:237: in __init__
self._num_buckets = num_buckets
../../../miniforge3/envs/pyiceberg/lib/python3.12/site-packages/pydantic/main.py:991: in __setattr__
setattr_handler(self, name, value) # call here to not memo on possibly unknown fields
../../../miniforge3/envs/pyiceberg/lib/python3.12/site-packages/pydantic/main.py:105: in <lambda>
'private': lambda model, name, val: model.__pydantic_private__.__setitem__(name, val), # pyright: ignore[reportOptionalMemberAccess]
E AttributeError: 'NoneType' object has no attribute '__setitem__'. Did you mean: '__setattr__'?
```
---
## After
Using `pydantic==2.11.0` the test
`test_transforms.py::test_bucket_hash_values` succeeds.
---
✅ Are these changes tested?
Yes
- No test was added to reproduce the bug because it is already
reproducible with the existing test
Co-authored-by: Zac Sanchez <za...@imc.com>
---
pyiceberg/transforms.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pyiceberg/transforms.py b/pyiceberg/transforms.py
index b8f0b975..7dfe7514 100644
--- a/pyiceberg/transforms.py
+++ b/pyiceberg/transforms.py
@@ -232,8 +232,8 @@ class BucketTransform(Transform[S, int]):
_num_buckets: PositiveInt = PrivateAttr()
def __init__(self, num_buckets: int, **data: Any) -> None:
- self._num_buckets = num_buckets
super().__init__(f"bucket[{num_buckets}]", **data)
+ self._num_buckets = num_buckets
@property
def num_buckets(self) -> int: