Fix: Handle HTTP 422 responses bypass to _process_response instead of raising immediately in Snowflake SQL API hook. #60891
+138
−17
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.
Summary
This PR adjusts the error-handling behavior of SnowflakeSqlApiHook so that HTTP 422 responses are not raised immediately by raise_for_status(), but instead passed through to _process_response() for Snowflake-specific error parsing.
(We already implemented message parsing method, but we haven't leveraged.)
Snowflake SQL API uses 422 (Unprocessable Entity) to return rich, structured error payloads (e.g. STATEMENT_ERROR, STATEMENT_NOT_FOUND, Compile Error).
Raising early discards this payload and prevents the hook from providing meaningful error context to users.
related: #60765
Details
Previously, raise_for_status() was called unconditionally, causing 422 responses to raise early and skip _process_response().
This PR updates the request flow:
Applies the same behavior to both sync and async API calls.
Tests
Added tests to verify that HTTP 422 does not call raise_for_status() and returns (status, body) for:
Added tests to confirm that HTTP 500 still raises and does not return a response body.
Refactored test helpers to make mocked HTTP responses more explicit and easier to control.
references
https://docs.snowflake.com/en/developer-guide/sql-api/reference
https://docs.snowflake.com/en/developer-guide/sql-api/reference#label-sql-api-reference-queryfailurestatus