From fefad80d8ac00265c1fc9514e8868714381e6973 Mon Sep 17 00:00:00 2001 From: platon Date: Mon, 29 Jun 2026 20:26:16 +0500 Subject: [PATCH 1/3] fix: raise ValidationError for decimal precision outside 1-38 range --- pyiceberg/types.py | 3 +++ tests/test_types.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pyiceberg/types.py b/pyiceberg/types.py index 3c98215366..8c33b1aa21 100644 --- a/pyiceberg/types.py +++ b/pyiceberg/types.py @@ -324,6 +324,9 @@ class DecimalType(PrimitiveType): root: tuple[int, int] def __init__(self, precision: int, scale: int) -> None: + if precision < 1 or precision > 38: + raise ValidationError(f"Decimal precision must be between 1 and 38: {precision}") + super().__init__(root=(precision, scale)) @model_serializer diff --git a/tests/test_types.py b/tests/test_types.py index 5e95687ba2..b04a5fed1f 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -920,3 +920,17 @@ def test_nested_field_geography_with_params_as_string() -> None: assert isinstance(field.field_type, GeographyType) assert field.field_type.crs == "EPSG:4326" assert field.field_type.algorithm == "planar" + +def test_decimal_precision_validation() -> None: + """Test that DecimalType rejects precision outside the [1, 38] range.""" + decimal_type = DecimalType(38, 2) + assert decimal_type.precision == 38 + + with pytest.raises(ValidationError, match="Decimal precision must be between 1 and 38"): + DecimalType(39, 2) + + with pytest.raises(ValidationError, match="Decimal precision must be between 1 and 38"): + DecimalType(0, 2) + + with pytest.raises(ValidationError, match="Decimal precision must be between 1 and 38"): + DecimalType(-5, 2) \ No newline at end of file From 6b8fe5b7183b366dbae45250aafc98bcdfa5af18 Mon Sep 17 00:00:00 2001 From: platon Date: Mon, 29 Jun 2026 20:40:20 +0500 Subject: [PATCH 2/3] style: fix formatting and end of file whitespace --- tests/test_types.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_types.py b/tests/test_types.py index b04a5fed1f..375fb9cdb6 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -921,6 +921,7 @@ def test_nested_field_geography_with_params_as_string() -> None: assert field.field_type.crs == "EPSG:4326" assert field.field_type.algorithm == "planar" + def test_decimal_precision_validation() -> None: """Test that DecimalType rejects precision outside the [1, 38] range.""" decimal_type = DecimalType(38, 2) @@ -933,4 +934,4 @@ def test_decimal_precision_validation() -> None: DecimalType(0, 2) with pytest.raises(ValidationError, match="Decimal precision must be between 1 and 38"): - DecimalType(-5, 2) \ No newline at end of file + DecimalType(-5, 2) From 50eaf6471f73d9d8b53b85594c804835cffca23c Mon Sep 17 00:00:00 2001 From: platon Date: Mon, 29 Jun 2026 20:46:37 +0500 Subject: [PATCH 3/3] test: fix invalid decimal precision in test_schema.py --- tests/test_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_schema.py b/tests/test_schema.py index 93ddc16202..aacdbc7d5e 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -67,7 +67,7 @@ FloatType(), DoubleType(), DecimalType(10, 2), - DecimalType(100, 2), + DecimalType(38, 2), StringType(), DateType(), TimeType(),