Skip to content

Commit 3f9edc2

Browse files
authored
SNOW-2217228 introduce snowflake_version property to connection (#2440)
1 parent e34a73c commit 3f9edc2

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1515
- Fixed a bug where timezoned timestamps fetched as pandas.DataFrame or pyarrow.Table would overflow for the sake of unnecessary precision. In the case where an overflow cannot be prevented a clear error will be raised now.
1616
- Fix OAuth authenticator values.
1717
- Add `unsafe_skip_file_permissions_check` flag to skip file permissions check on cache and config.
18+
- Introduce snowflake_version property to the connection
1819

1920
- v3.16.0(July 04,2025)
2021
- Bumped numpy dependency from <2.1.0 to <=2.2.4.

src/snowflake/connector/connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from concurrent.futures.thread import ThreadPoolExecutor
1616
from contextlib import suppress
1717
from difflib import get_close_matches
18-
from functools import partial
18+
from functools import cached_property, partial
1919
from io import StringIO
2020
from logging import getLogger
2121
from threading import Lock
@@ -884,6 +884,14 @@ def unsafe_file_write(self, value: bool) -> None:
884884
def check_arrow_conversion_error_on_every_column(self) -> bool:
885885
return self._check_arrow_conversion_error_on_every_column
886886

887+
@cached_property
888+
def snowflake_version(self) -> str:
889+
# The result from SELECT CURRENT_VERSION() is `<version> <internal hash>`,
890+
# and we only need the first part
891+
return str(
892+
self.cursor().execute("SELECT CURRENT_VERSION()").fetchall()[0][0]
893+
).split(" ")[0]
894+
887895
@check_arrow_conversion_error_on_every_column.setter
888896
def check_arrow_conversion_error_on_every_column(self, value: bool) -> bool:
889897
self._check_arrow_conversion_error_on_every_column = value

test/integ/test_connection.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,3 +1693,27 @@ def _run_select_1(unsafe_skip_file_permissions_check: bool):
16931693
assert (
16941694
len(permission_warnings) == 0
16951695
), "Expected no permission warning when unsafe_skip_file_permissions_check=True"
1696+
1697+
1698+
# The property snowflake_version is newly introduced and therefore should not be tested on old drivers.
1699+
@pytest.mark.skipolddriver
1700+
def test_snowflake_version():
1701+
import re
1702+
1703+
conn = create_connection("default")
1704+
# Assert that conn has a snowflake_version attribute
1705+
assert hasattr(
1706+
conn, "snowflake_version"
1707+
), "conn should have a snowflake_version attribute"
1708+
1709+
# Assert that conn.snowflake_version is a string.
1710+
assert isinstance(
1711+
conn.snowflake_version, str
1712+
), f"snowflake_version should be a string, but got {type(conn.snowflake_version)}"
1713+
1714+
# Assert that conn.snowflake_version is in the format of "x.y.z", where
1715+
# x, y and z are numbers.
1716+
version_pattern = r"^\d+\.\d+\.\d+$"
1717+
assert re.match(
1718+
version_pattern, conn.snowflake_version
1719+
), f"snowflake_version should match pattern 'x.y.z', but got '{conn.snowflake_version}'"

0 commit comments

Comments
 (0)