From 495c99bc951912dd04e257c9bd2e6f177627f3f8 Mon Sep 17 00:00:00 2001 From: ericf-firebolt Date: Thu, 20 Jan 2022 11:26:12 -0500 Subject: [PATCH 1/3] Added decimal.Decimal to _types.py. --- src/firebolt/async_db/_types.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/firebolt/async_db/_types.py b/src/firebolt/async_db/_types.py index 9ad06e2cd48..45974ecdcf1 100644 --- a/src/firebolt/async_db/_types.py +++ b/src/firebolt/async_db/_types.py @@ -2,6 +2,7 @@ from collections import namedtuple from datetime import date, datetime, timezone +from decimal import Decimal from enum import Enum from typing import Sequence, Union @@ -177,7 +178,7 @@ def parse_value( """Provided raw value and python type, parses first into python value.""" if value is None: return None - if ctype in (int, str, float): + if ctype in (int, str, float, Decimal): assert isinstance(ctype, type) return ctype(value) if ctype is date: @@ -206,7 +207,7 @@ def format_value(value: ParameterType) -> str: """For python value to be used in a SQL query""" if isinstance(value, bool): return str(int(value)) - if isinstance(value, (int, float)): + if isinstance(value, (int, float, Decimal)): return str(value) elif isinstance(value, str): return f"'{''.join(escape_chars.get(c, c) for c in value)}'" From 2ce3c2f7a52a2ffd804ad1ac86e7b8b5aa767c09 Mon Sep 17 00:00:00 2001 From: ericf-firebolt Date: Mon, 24 Jan 2022 09:31:02 -0500 Subject: [PATCH 2/3] Removed Decimal as type from parse_value() in _types.py. --- src/firebolt/async_db/_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/firebolt/async_db/_types.py b/src/firebolt/async_db/_types.py index 45974ecdcf1..0f3e5616376 100644 --- a/src/firebolt/async_db/_types.py +++ b/src/firebolt/async_db/_types.py @@ -178,7 +178,7 @@ def parse_value( """Provided raw value and python type, parses first into python value.""" if value is None: return None - if ctype in (int, str, float, Decimal): + if ctype in (int, str, float): assert isinstance(ctype, type) return ctype(value) if ctype is date: From 401090e220d962121fa1c4f55ef04b4d200c87dc Mon Sep 17 00:00:00 2001 From: ericf-firebolt Date: Mon, 24 Jan 2022 13:06:35 -0500 Subject: [PATCH 3/3] Added two unit tests for Decimal.decimal, one sending in a float and one a string. --- tests/unit/async_db/test_typing_format.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/async_db/test_typing_format.py b/tests/unit/async_db/test_typing_format.py index bb03b79b29d..60fd4b9b1e0 100644 --- a/tests/unit/async_db/test_typing_format.py +++ b/tests/unit/async_db/test_typing_format.py @@ -1,4 +1,5 @@ from datetime import date, datetime, timedelta, timezone +from decimal import Decimal from pytest import mark, raises @@ -17,6 +18,8 @@ # Numbers (1, "1"), (1.123, "1.123"), + (Decimal("1.123"), "1.123"), + (Decimal(1.123), "1.1229999999999999982236431605997495353221893310546875"), (True, "1"), (False, "0"), # Date, datetime