Fix creation of Bucket Transforms with pydantic>=2.11.0#1881
Merged
Fokko merged 1 commit intoapache:mainfrom Apr 4, 2025
Merged
Fix creation of Bucket Transforms with pydantic>=2.11.0#1881Fokko merged 1 commit intoapache:mainfrom
Fokko merged 1 commit intoapache:mainfrom
Conversation
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`.
Fokko
pushed a commit
that referenced
this pull request
Apr 17, 2025
## 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 <zac.sanchez@imc.com>
gabeiglio
pushed a commit
to Netflix/iceberg-python
that referenced
this pull request
Aug 13, 2025
## 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 <zac.sanchez@imc.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onself.Before
Using
pydantic==2.11.0the testtest_transforms.py::test_bucket_hash_valuesfailsAfter
Using
pydantic==2.11.0the testtest_transforms.py::test_bucket_hash_valuessucceeds.✅ Are these changes tested?
Yes