Repository navigation
Commit c209332
authored
fix: raise
Closes #3583
# Rationale for this change
According to the Iceberg specification, decimal precision must be
between 1 and 38. Previously, `pyiceberg` silently accepted invalid
values (such as `precision=39` or `0`), which could lead to data
corruption or crashes downstream when encoding/decoding fixed-byte
decimals (matching the Java implementation's
`IllegalArgumentException`).
This PR adds a defensive validation guard into `DecimalType.__init__` to
raise a `ValidationError` when the precision is out of bounds `[1, 38]`.
Additionally, fixed an existing invalid type definition
(`DecimalType(100, 2)`) inside `tests/test_schema.py` which was
violating the specification bounds and causing the new validation guard
to trip during the integration test suite.
## Are these changes tested?
Yes, added dedicated unit tests in `tests/test_types.py`:
- `test_decimal_precision_validation` covers upper bounds
(`precision=39`), lower bounds (`precision=0`, `precision=-5`), and
ensures valid boundary values (`precision=38`) work perfectly.
Also updated existing test assertions in `tests/test_schema.py` to use a
compliant precision value (`38`).
## Are there any user-facing changes?
Yes, creating a `DecimalType` with an invalid precision will now
explicitly raise a `pyiceberg.exceptions.ValidationError` instead of
failing silently at runtime.ValidationError for decimal precision outside range (#3585)1 parent ea80d51 commit c209332
3 files changed
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
329 | 337 | | |
330 | 338 | | |
331 | 339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
920 | 920 | | |
921 | 921 | | |
922 | 922 | | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
0 commit comments