From 28c76f1cd1c1896156b2876770c03816078b0c79 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sat, 7 Feb 2026 22:39:53 -0300 Subject: [PATCH 1/4] fix: remove normalize() from round_decimal to preserve precision Decimal.normalize() strips trailing zeros, causing serialize(deserialize(x)) != x for values like "1.000000". Removing it preserves the quantized precision. Closes #28 --- l9format/l9format.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/l9format/l9format.py b/l9format/l9format.py index 74b46a9..4bf6102 100644 --- a/l9format/l9format.py +++ b/l9format/l9format.py @@ -6,9 +6,7 @@ def round_decimal( decimal_obj: decimal.Decimal, num_of_places: int = 6 ) -> decimal.Decimal: - return decimal_obj.quantize( - decimal.Decimal(10) ** -num_of_places - ).normalize() + return decimal_obj.quantize(decimal.Decimal(10) ** -num_of_places) class Decimal(fields.Instance): From a88c8c8dbe6a96ff130a078ec8b5a0cb93418a6c Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sat, 7 Feb 2026 22:40:49 -0300 Subject: [PATCH 2/4] CHANGELOG: fix Decimal.normalize() precision loss (#28) --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4560660..1473db3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to ### Fixed - Fix leaked file handles in tests using context managers ([b66a6f5], [#25]) +- Fix `Decimal.normalize()` stripping trailing zeros, breaking round-trip + serialization ([28c76f1], [#28]) - Fix typo in test name: `test_l9events_form_ip4scout` -> `test_l9events_from_ip4scout` ([0d8736e], [#27]) @@ -152,6 +154,7 @@ and this project adheres to +[28c76f1]: https://github.com/LeakIX/l9format-python/commit/28c76f1 [b66a6f5]: https://github.com/LeakIX/l9format-python/commit/b66a6f5 [cbea4fc]: https://github.com/LeakIX/l9format-python/commit/cbea4fc [3547e22]: https://github.com/LeakIX/l9format-python/commit/3547e22 @@ -221,6 +224,7 @@ and this project adheres to [#21]: https://github.com/LeakIX/l9format-python/issues/21 [#22]: https://github.com/LeakIX/l9format-python/issues/22 [#26]: https://github.com/LeakIX/l9format-python/issues/26 +[#28]: https://github.com/LeakIX/l9format-python/issues/28 [#27]: https://github.com/LeakIX/l9format-python/issues/27 [#33]: https://github.com/LeakIX/l9format-python/issues/33 [#25]: https://github.com/LeakIX/l9format-python/issues/25 From 013074319b410418226954311673c6eea1bc21ce Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sat, 7 Feb 2026 22:46:31 -0300 Subject: [PATCH 3/4] test: add round-trip regression test for Decimal precision Ensures serialize(deserialize(x)) preserves values, guarding against re-introduction of normalize() which strips trailing zeros. --- tests/test_validation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_validation.py b/tests/test_validation.py index 69bbb80..e506869 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -303,6 +303,14 @@ def test_geopoint_negative_values(self) -> None: assert gp.lat == -1.5 assert gp.lon == -2.5 + def test_geopoint_round_trip_preserves_value(self) -> None: + """Regression: normalize() used to strip trailing zeros.""" + gp = GeoPoint.from_dict({"lat": "1.000000", "lon": "2.500000"}) + serialized = gp.to_dict() + gp2 = GeoPoint.from_dict(serialized) + assert gp2.lat == gp.lat + assert gp2.lon == gp.lon + class TestComplexNestedValidation: """Test validation behavior with complex nested structures.""" From 23b3cc2c808562cba6adcf43b5e478204f165463 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sat, 7 Feb 2026 22:47:21 -0300 Subject: [PATCH 4/4] CHANGELOG: fix Decimal.normalize() precision loss (#28) --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1473db3..9a3d0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ and this project adheres to - Fix leaked file handles in tests using context managers ([b66a6f5], [#25]) - Fix `Decimal.normalize()` stripping trailing zeros, breaking round-trip - serialization ([28c76f1], [#28]) + serialization; add regression test ([28c76f1], [0130743], [#28]) - Fix typo in test name: `test_l9events_form_ip4scout` -> `test_l9events_from_ip4scout` ([0d8736e], [#27]) @@ -154,6 +154,7 @@ and this project adheres to +[0130743]: https://github.com/LeakIX/l9format-python/commit/0130743 [28c76f1]: https://github.com/LeakIX/l9format-python/commit/28c76f1 [b66a6f5]: https://github.com/LeakIX/l9format-python/commit/b66a6f5 [cbea4fc]: https://github.com/LeakIX/l9format-python/commit/cbea4fc