Repository navigation
Fix Snowflake SQL API wait_for_query timing out on finished queries - #73761
Merged
potiuk merged 2 commits intoOct 5, 2026
Merged
Conversation
justinpakzad
approved these changes
Sep 26, 2026
justinpakzad
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR, the change makes sense to me.
wait_for_query checked the elapsed time before looking at the status it had just fetched, so a status call that returned after the timeout raised TimeoutError even when the query had already succeeded or failed. Status calls can take several seconds because they retry with exponential backoff, and the OpenLineage integration waits with a 3-second timeout, so a finished query could be reported as timed out and its lineage details dropped. Elapsed time now also uses the monotonic clock so wall-clock adjustments cannot shorten or extend the wait.
potiuk
force-pushed
the
snowflake-wait-for-query-timeout
branch
from
October 4, 2026 23:48
c8ef66b to
6aa8982
Compare
potiuk
approved these changes
Oct 5, 2026
potiuk
left a comment
Member
There was a problem hiding this comment.
The ordering fix is right: a query that already finished is reported even when the status call itself ran past the timeout, and a query still running past the timeout still raises. time.monotonic() is the right clock for this, and mocking it is needed since time_machine doesn't control the monotonic clock. Thanks!
Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting
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.
SnowflakeSqlApiHook.wait_for_querychecked the elapsed time before it looked at the status it had just fetched. If the status call itself returned after the timeout, the method raisedTimeoutErroreven when that status showed the query had already finished (successorerror).This is easy to hit in practice. Each status call goes through
_make_api_call_with_retries, which retries 429/503/504 and connection errors with exponential backoff, so one call can take several seconds. The only caller in the provider, the OpenLineage helper_run_single_query_with_api_hook, usestimeout=3. A slow but successful status check therefore surfaced as a timeout, and the query-history details for lineage were dropped.Changes:
TimeoutErroris raised only while the query is stillrunningtime.monotonic()instead oftime.time(), so wall-clock adjustments (NTP sync, DST) cannot cut the wait short or stretch itTests:
test_wait_for_query_returns_finished_status_after_timeout_elapsed(parametrized forsuccessanderror): a single status call that takes longer than the timeout returns the finished status instead of raising. It fails with the previous check order.test_wait_for_query_timeout_errornow drives a fake monotonic clock, becausetime_machinedoes not movetime.monotonic(). It still asserts the same number of polls and sleeps beforeTimeoutError.Checks run locally:
uv run --project providers/snowflake pytest tests/unit/snowflake/hooks/test_snowflake_sql_api.py: 91 passeduv run --project providers/snowflake pytest tests/unit/snowflake/utils/test_openlineage.py: 48 passedprek run --stage pre-commiton the changed files: 45 hooks passed.check-provider-yaml-validneeds the Breeze CI image and could not run locally (noprovider.yamlchange here);ast-grepwas skipped because it could not download its Node runtime.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines