fix: raise `ValidationError` for decimal precision outside range (#3585)

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.
3 files changed
tree: a3636f5814bf9d0e7c1c87936ae90b8b13f24796
  1. .github/
  2. dev/
  3. mkdocs/
  4. notebooks/
  5. pyiceberg/
  6. tests/
  7. vendor/
  8. .asf.yaml
  9. .codespellrc
  10. .gitignore
  11. .markdownlint.yaml
  12. .pre-commit-config.yaml
  13. AGENTS.md
  14. LICENSE
  15. Makefile
  16. MANIFEST.in
  17. NOTICE
  18. pyproject.toml
  19. README.md
  20. ruff.toml
  21. SECURITY-THREAT-MODEL.md
  22. setup.py
  23. uv.lock
README.md

Iceberg Python

PyIceberg is a Python library for programmatic access to Iceberg table metadata as well as to table data in Iceberg format. It is a Python implementation of the Iceberg table spec.

The documentation is available at https://py.iceberg.apache.org/.

Get in Touch