From 4b384313d2dc4e853768d54c52a57665408e677d Mon Sep 17 00:00:00 2001 From: Jeff Sawatzky Date: Tue, 6 May 2025 01:11:46 -0400 Subject: [PATCH 1/4] fix: ensure we run to_snowflake on list items. Fixes #2311 --- src/snowflake/connector/converter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/snowflake/connector/converter.py b/src/snowflake/connector/converter.py index 820235199..5e7c6efc6 100644 --- a/src/snowflake/connector/converter.py +++ b/src/snowflake/connector/converter.py @@ -5,9 +5,8 @@ import decimal import json import time -from datetime import date, datetime +from datetime import date, datetime, timedelta, timezone, tzinfo from datetime import time as dt_t -from datetime import timedelta, timezone, tzinfo from functools import partial from logging import getLogger from math import ceil @@ -623,8 +622,8 @@ def _decimal_to_snowflake(self, value: decimal.Decimal) -> str | None: def _list_to_snowflake(self, value: list) -> list: return [ - SnowflakeConverter.quote(v0) - for v0 in [SnowflakeConverter.escape(v) for v in value] + SnowflakeConverter.quote(SnowflakeConverter.escape(self.to_snowflake(v))) + for v in value ] _tuple_to_snowflake = _list_to_snowflake From 11a0b1b52fedffc9c4582d966577dccffec789cb Mon Sep 17 00:00:00 2001 From: Jeff Sawatzky Date: Fri, 9 May 2025 12:41:42 -0400 Subject: [PATCH 2/4] chore: add a test --- test/unit/test_converter.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/unit/test_converter.py b/test/unit/test_converter.py index 37f41172f..3dede96ca 100644 --- a/test/unit/test_converter.py +++ b/test/unit/test_converter.py @@ -4,6 +4,7 @@ from datetime import timedelta from decimal import Decimal from logging import getLogger +from uuid import UUID import numpy import pytest @@ -41,9 +42,9 @@ def test_is_dst(): m = conv.to_python_method("TIMESTAMP_LTZ", col_meta) ret = m("1414890189.000") - assert ( - str(ret) == "2014-11-01 18:03:09-07:00" - ), "Timestamp during from DST to non-DST" + assert str(ret) == "2014-11-01 18:03:09-07:00", ( + "Timestamp during from DST to non-DST" + ) # non-DST to DST col_meta = { @@ -57,9 +58,9 @@ def test_is_dst(): m = conv.to_python_method("TIMESTAMP_LTZ", col_meta) ret = m("1425780189.000") - assert ( - str(ret) == "2015-03-07 18:03:09-08:00" - ), "Timestamp during from non-DST to DST" + assert str(ret) == "2015-03-07 18:03:09-08:00", ( + "Timestamp during from non-DST to DST" + ) def test_more_timestamps(): @@ -77,6 +78,13 @@ def test_more_timestamps(): assert m("-2208943503.0120000") == "1900-01-01 12:34:56.988000000" +def test_converter_to_snowflake_bytes(): + uuid = UUID("12345678-1234-5678-1234-567812345678") + + converter = SnowflakeConverter() + assert converter.to_snowflake([uuid.bytes]) == ["X'\x124Vx\x124Vx\x124Vx\x124Vx'"] + + def test_converter_to_snowflake_error(): converter = SnowflakeConverter() with pytest.raises( From d3a819cb5926800df601f77d941dc9e9eb8b39c5 Mon Sep 17 00:00:00 2001 From: Piotr Bulawa Date: Mon, 12 May 2025 13:20:58 +0200 Subject: [PATCH 3/4] Format --- src/snowflake/connector/converter.py | 3 ++- test/unit/test_converter.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/snowflake/connector/converter.py b/src/snowflake/connector/converter.py index 5e7c6efc6..fa8348226 100644 --- a/src/snowflake/connector/converter.py +++ b/src/snowflake/connector/converter.py @@ -5,8 +5,9 @@ import decimal import json import time -from datetime import date, datetime, timedelta, timezone, tzinfo +from datetime import date, datetime from datetime import time as dt_t +from datetime import timedelta, timezone, tzinfo from functools import partial from logging import getLogger from math import ceil diff --git a/test/unit/test_converter.py b/test/unit/test_converter.py index 3dede96ca..2e29b036c 100644 --- a/test/unit/test_converter.py +++ b/test/unit/test_converter.py @@ -42,9 +42,9 @@ def test_is_dst(): m = conv.to_python_method("TIMESTAMP_LTZ", col_meta) ret = m("1414890189.000") - assert str(ret) == "2014-11-01 18:03:09-07:00", ( - "Timestamp during from DST to non-DST" - ) + assert ( + str(ret) == "2014-11-01 18:03:09-07:00" + ), "Timestamp during from DST to non-DST" # non-DST to DST col_meta = { @@ -58,9 +58,9 @@ def test_is_dst(): m = conv.to_python_method("TIMESTAMP_LTZ", col_meta) ret = m("1425780189.000") - assert str(ret) == "2015-03-07 18:03:09-08:00", ( - "Timestamp during from non-DST to DST" - ) + assert ( + str(ret) == "2015-03-07 18:03:09-08:00" + ), "Timestamp during from non-DST to DST" def test_more_timestamps(): From dab6ecaa2c23cf10b82bbe67a771ae5853d3596f Mon Sep 17 00:00:00 2001 From: Piotr Bulawa Date: Mon, 12 May 2025 13:22:44 +0200 Subject: [PATCH 4/4] Description --- DESCRIPTION.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION.md b/DESCRIPTION.md index 99ca0e831..6b9e6a419 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -10,6 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne - v3.16(TBD) - Added basic arrow support for Interval types. - Fix `write_pandas` special characters usage in the location name. + - Ensure the converter runs to_snowflake on list items. - v3.15.0(Apr 29,2025) - Bumped up min boto and botocore version to 1.24.