Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError in SnowflakeConnector.fetch_all #16511

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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
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
Loading