fix(snowflake): close() swallows a failing cursor reset - #22800
Merged
desertaxle merged 1 commit intoAug 10, 2026
Conversation
SnowflakeConnector.close() calls reset_cursors() inside try and returns from the finally block when there is no open connection. Returning out of a finally discards the exception that was propagating, so a reset_cursors() failure on a connector that never opened a connection is reported to the caller as a clean close. Replace the early return with an if/else so the block falls off the end and the in-flight exception continues to propagate. The logged messages and the connection teardown are unchanged. Added a regression test; with the early return restored it fails with 'DID NOT RAISE RuntimeError'.
noron12234
requested review from
chrisguidry,
desertaxle and
zzstoatzz
as code owners
August 10, 2026 15:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SnowflakeConnector.close()returns out of itsfinallyblock:A
returninsidefinallydiscards whatever exception was propagating. So ifreset_cursors()raises on a connector that never opened a connection — the_connection is Nonepath — the caller is told the close succeeded and theoriginal error is gone.
That is the exact shape that hides cursor-cleanup failures during teardown,
including inside
__exit__, where the connector is closed on the way out of awithblock that may itself already be unwinding.Fix
Replace the early return with an
if/elseso thefinallyblock falls offthe end. Logged messages and the connection teardown are byte-for-byte the same;
the only behavioural change is that an exception from
reset_cursors()nowreaches the caller.
Test
Added
test_close_propagates_a_failing_cursor_resetnext to the existingtest_close. It monkeypatchesreset_cursorsto raise and asserts the errorescapes
close().With the early
returnrestored, it fails:pytest src/integrations/prefect-snowflake/tests/test_database.py -k close→ 2 passed.
ruff format --checkclean on both files.