fix: raise ValidationError for decimal precision outside 1-38 range#3585
Open
PLTNGM wants to merge 3 commits into
Open
fix: raise ValidationError for decimal precision outside 1-38 range#3585PLTNGM wants to merge 3 commits into
PLTNGM wants to merge 3 commits into
Conversation
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.
Closes #3583
Rationale for this change
According to the Iceberg specification, decimal precision must be between 1 and 38. Previously,
pyicebergsilently accepted invalid values (such asprecision=39or0), which could lead to data corruption or crashes downstream when encoding/decoding fixed-byte decimals (matching the Java implementation'sIllegalArgumentException).This PR adds a defensive validation guard into
DecimalType.__init__to raise aValidationErrorwhen the precision is out of bounds[1, 38].Additionally, fixed an existing invalid type definition (
DecimalType(100, 2)) insidetests/test_schema.pywhich 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_validationcovers 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.pyto use a compliant precision value (38).Are there any user-facing changes?
Yes, creating a
DecimalTypewith an invalid precision will now explicitly raise apyiceberg.exceptions.ValidationErrorinstead of failing silently at runtime.