Skip to content

Commit

Permalink
SNOW-1511108 SQLAlchemy heartbeat frequency parsed as string (#1993)
Browse files Browse the repository at this point in the history
* SNOW-1511108 SQLAlchemy heartbeat frequency parsed as string
  • Loading branch information
sfc-gh-dszmolka authored Jul 15, 2024
1 parent 184d5c7 commit 4a89dad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne

- v3.12.0(TBD)
- Optimized `to_pandas()` performance by fully parallel downloading logic.

- Fixed a bug that specifying client_session_keep_alive_heartbeat_frequency in snowflake-sqlalchemy could crash the connector

- v3.11.0(June 17,2024)
- Added support for `token_file_path` connection parameter to read an OAuth token from a file when connecting to Snowflake.
Expand Down
10 changes: 6 additions & 4 deletions src/snowflake/connector/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,12 @@ def _validate_client_session_keep_alive_heartbeat_frequency(self) -> int:
"""Validate and return heartbeat frequency in seconds."""
real_max = int(self.rest.master_validity_in_seconds / 4)
real_min = int(real_max / 4)

# ensure the type is integer
self._client_session_keep_alive_heartbeat_frequency = int(
self.client_session_keep_alive_heartbeat_frequency
)

if self.client_session_keep_alive_heartbeat_frequency is None:
# This is an unlikely scenario but covering it just in case.
self._client_session_keep_alive_heartbeat_frequency = real_min
Expand All @@ -1681,10 +1687,6 @@ def _validate_client_session_keep_alive_heartbeat_frequency(self) -> int:
elif self.client_session_keep_alive_heartbeat_frequency < real_min:
self._client_session_keep_alive_heartbeat_frequency = real_min

# ensure the type is integer
self._client_session_keep_alive_heartbeat_frequency = int(
self.client_session_keep_alive_heartbeat_frequency
)
return self.client_session_keep_alive_heartbeat_frequency

def _validate_client_prefetch_threads(self) -> int:
Expand Down
4 changes: 3 additions & 1 deletion test/integ/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ def test_keep_alive_heartbeat_frequency(db_parameters):
cnx.close()


@pytest.mark.skipolddriver
def test_keep_alive_heartbeat_frequency_min(db_parameters):
"""Tests heartbeat setting with custom frequency.
Creates a connection with client_session_keep_alive_heartbeat_frequency parameter and set the minimum frequency.
Also if a value comes as string, should be properly converted to int and not fail assertion.
"""
config = {
"user": db_parameters["user"],
Expand All @@ -249,7 +251,7 @@ def test_keep_alive_heartbeat_frequency_min(db_parameters):
"protocol": db_parameters["protocol"],
"timezone": "UTC",
"client_session_keep_alive": True,
"client_session_keep_alive_heartbeat_frequency": 10,
"client_session_keep_alive_heartbeat_frequency": "10",
}
cnx = snowflake.connector.connect(**config)
try:
Expand Down

0 comments on commit 4a89dad

Please sign in to comment.