From 68449ab19352a3df2fb986c061af6b42cc590402 Mon Sep 17 00:00:00 2001 From: ptiurin Date: Tue, 29 Apr 2025 11:01:01 +0100 Subject: [PATCH 1/2] fix: Decimal parsing from float --- src/firebolt/common/_types.py | 4 ++++ tests/unit/common/test_typing_parse.py | 1 + 2 files changed, 5 insertions(+) diff --git a/src/firebolt/common/_types.py b/src/firebolt/common/_types.py index d3653f93ea..3efbf7b392 100644 --- a/src/firebolt/common/_types.py +++ b/src/firebolt/common/_types.py @@ -343,6 +343,10 @@ def parse_value( if isinstance(ctype, DECIMAL): if not isinstance(value, (str, int, float)): raise DataError(f"Invalid decimal value {value}: str or int expected") + if isinstance(value, float): + # Decimal constructor doesn't support float + # so we need to convert it to string first + value = str(value) return Decimal(value) if isinstance(ctype, ARRAY): if not isinstance(value, list): diff --git a/tests/unit/common/test_typing_parse.py b/tests/unit/common/test_typing_parse.py index 8d24155c6f..9c007b6281 100644 --- a/tests/unit/common/test_typing_parse.py +++ b/tests/unit/common/test_typing_parse.py @@ -219,6 +219,7 @@ def test_parse_value_datetime_errors() -> None: [ ("123.456", Decimal("123.456")), (123, Decimal("123")), + (123.456, Decimal("123.456")), (None, None), ], ) From f8151293ce761c71f3f7d5432d5bca015ba77287 Mon Sep 17 00:00:00 2001 From: ptiurin Date: Tue, 29 Apr 2025 11:03:54 +0100 Subject: [PATCH 2/2] fix test --- tests/unit/common/test_typing_parse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/common/test_typing_parse.py b/tests/unit/common/test_typing_parse.py index 9c007b6281..54e3281a96 100644 --- a/tests/unit/common/test_typing_parse.py +++ b/tests/unit/common/test_typing_parse.py @@ -226,7 +226,7 @@ def test_parse_value_datetime_errors() -> None: def test_parse_decimal(value, expected) -> None: assert ( parse_value(value, DECIMAL(38, 3)) == expected - ), "Error parsing decimal(38, 3): provided {value}, expected {expected}" + ), f"Error parsing decimal(38, 3): provided {value}, expected {expected}" @mark.parametrize(