Skip to content

Commit abe0d56

Browse files
authored
fix(NoTicket): Decimal parsing from float (#428)
1 parent 1296570 commit abe0d56

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/firebolt/common/_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ def parse_value(
343343
if isinstance(ctype, DECIMAL):
344344
if not isinstance(value, (str, int, float)):
345345
raise DataError(f"Invalid decimal value {value}: str or int expected")
346+
if isinstance(value, float):
347+
# Decimal constructor doesn't support float
348+
# so we need to convert it to string first
349+
value = str(value)
346350
return Decimal(value)
347351
if isinstance(ctype, ARRAY):
348352
if not isinstance(value, list):

tests/unit/common/test_typing_parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,14 @@ def test_parse_value_datetime_errors() -> None:
219219
[
220220
("123.456", Decimal("123.456")),
221221
(123, Decimal("123")),
222+
(123.456, Decimal("123.456")),
222223
(None, None),
223224
],
224225
)
225226
def test_parse_decimal(value, expected) -> None:
226227
assert (
227228
parse_value(value, DECIMAL(38, 3)) == expected
228-
), "Error parsing decimal(38, 3): provided {value}, expected {expected}"
229+
), f"Error parsing decimal(38, 3): provided {value}, expected {expected}"
229230

230231

231232
@mark.parametrize(

0 commit comments

Comments
 (0)