Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## v1.11.1 5/20/26
- Reset Snowflake connection to None when it's closed

## v1.11.0 4/27/26
- Allow Snowflake client to connect using any parameters

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "nypl_py_utils"
version = "1.11.0"
version = "1.11.1"
authors = [
{ name="Aaron Friedman", email="aaronfriedman@nypl.org" },
]
Expand Down
4 changes: 2 additions & 2 deletions src/nypl_py_utils/classes/s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set_cache(self, state):
except ClientError as e:
error_msg = (
f'Error uploading {self.resource} to S3 bucket '
f'{self.s3_bucket}: {e}')
f'{self.bucket}: {e}')
self.logger.error(error_msg)
raise S3ClientError(error_msg) from None

Expand All @@ -83,7 +83,7 @@ def upload_file(self, content, file_path):
except ClientError as e:
error_msg = (
f'Error uploading {file_path} to S3 bucket '
f'{self.s3_bucket}: {e}')
f'{self.bucket}: {e}')
self.logger.error(error_msg)
raise S3ClientError(error_msg) from None

Expand Down
1 change: 1 addition & 0 deletions src/nypl_py_utils/classes/snowflake_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def close_connection(self):
"""Closes the connection"""
self.logger.info('Closing Snowflake connection')
self.conn.close()
self.conn = None


class SnowflakeClientError(Exception):
Expand Down
18 changes: 14 additions & 4 deletions tests/test_snowflake_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,28 @@ def test_execute_query(
def test_execute_query_with_exception(
self, mock_snowflake_conn, test_instance, mocker):
test_instance.connect()
test_conn = test_instance.conn

mock_cursor = mocker.MagicMock()
mock_cursor.execute.side_effect = Exception()
test_instance.conn.cursor.return_value = mock_cursor
test_conn.cursor.return_value = mock_cursor

with pytest.raises(SnowflakeClientError):
test_instance.execute_query('test query')

mock_cursor.close.assert_called()
test_instance.conn.close.assert_called_once()
test_conn.close.assert_called_once()

def test_close_connection(
self, mock_snowflake_conn, test_instance, mocker):
assert test_instance.conn is None

def test_close_connection(self, mock_snowflake_conn, test_instance):
test_instance.connect()

test_conn = test_instance.conn
assert test_conn is not None

test_instance.close_connection()
test_instance.conn.close.assert_called_once()

test_conn.close.assert_called_once()
assert test_instance.conn is None
Loading