Skip to content

Commit

Permalink
Fix TypeError in SnowflakeConnector.fetch_all (#16511)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz authored Dec 26, 2024
1 parent a3d85c1 commit 05cb591
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,7 @@ def fetch_all(
)
new, cursor = self._get_cursor(inputs, cursor_type)
if new:
self.execute(
operation, parameters, cursor_type=cursor_type, **execute_kwargs
)
cursor.execute(operation, params=parameters, **execute_kwargs)
self.logger.debug("Preparing to fetch all rows.")
return cursor.fetchall()

Expand Down
15 changes: 15 additions & 0 deletions src/integrations/prefect-snowflake/tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,21 @@ def test_fetch_all_cursor_default(self, snowflake_connector: SnowflakeConnector)

assert args[0] == OriginalSnowflakeCursorClass

def test_fetch_all_executes_directly_on_cursor(
self, snowflake_connector: SnowflakeConnector
):
"""Test that fetch_all executes directly on the cursor instead of using self.execute."""
snowflake_connector._start_connection()
mock_cursor = MagicMock()
snowflake_connector._connection.cursor.return_value = mock_cursor
mock_cursor.fetchall.return_value = [(1,)]

result = snowflake_connector.fetch_all("SELECT 1")

mock_cursor.execute.assert_called_once_with("SELECT 1", params=None)
mock_cursor.fetchall.assert_called_once()
assert result == [(1,)]

@pytest.mark.parametrize("fetch_function_name", ["fetch_many", "fetch_many_async"])
async def test_fetch_many(self, fetch_function_name, snowflake_connector):
fetch_function = getattr(snowflake_connector, fetch_function_name)
Expand Down

0 comments on commit 05cb591

Please sign in to comment.