Skip to content

fix: raise ValidationError for decimal precision outside 1-38 range#3585

Open
PLTNGM wants to merge 3 commits into
apache:mainfrom
PLTNGM:fix-decimal-precision-validation
Open

fix: raise ValidationError for decimal precision outside 1-38 range#3585
PLTNGM wants to merge 3 commits into
apache:mainfrom
PLTNGM:fix-decimal-precision-validation

Conversation

@PLTNGM

@PLTNGM PLTNGM commented Jun 29, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimal Should Reject precision > 38

1 participant