From c762b413c7ca5dd5a0c0b5c8fcc556ec2c6f49fa Mon Sep 17 00:00:00 2001 From: Haowei Yu Date: Tue, 28 Jul 2026 18:07:58 +0000 Subject: [PATCH] Download model files via session.file.get instead of GET+collect ModelVersionSQLClient.get_file's non-stored-procedure branch runs a raw `GET snow://model/... file://...` through DataFrame.collect(). In environments that wrap collect() -- e.g. Snowflake Container Runtime notebooks patch it into a cancellable async job -- a GET has no result set that can be replayed via result_scan, so ModelVersion.load() fails with `ProgrammingError 000710 (02000): Result for query has expired`. Use session.file.get (the FileOperation API that mirrors the session.file.put used when logging a model); it goes through the connector file-transfer path and does not depend on collect(). This also makes upload/download symmetric. Co-Authored-By: Claude Opus 4.8 --- snowflake/ml/model/_client/sql/model_version.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/snowflake/ml/model/_client/sql/model_version.py b/snowflake/ml/model/_client/sql/model_version.py index 8934f1b5..22ac2dd6 100644 --- a/snowflake/ml/model/_client/sql/model_version.py +++ b/snowflake/ml/model/_client/sql/model_version.py @@ -289,7 +289,6 @@ def get_file( scheme="snow", netloc="model", path=stage_location, params="", query="", fragment="" ).geturl() local_location = target_path.resolve().as_posix() - local_location_url = f"file://{local_location}" if snowpark_utils.is_in_stored_procedure(): # type: ignore[no-untyped-call] options = {"parallel": 10} @@ -297,11 +296,14 @@ def get_file( cursor._download(stage_location_url, str(target_path), options) cursor.fetchall() else: - query_result_checker.SqlResultValidator( - self._session, - f"GET {_normalize_url_for_sql(stage_location_url)} {_normalize_url_for_sql(local_location_url)}", - statement_params=statement_params, - ).has_dimensions(expected_rows=1).validate() + get_results = self._session.file.get( + stage_location_url, local_location, statement_params=statement_params + ) + if len(get_results) != 1: + raise ValueError( + f"Expected to download exactly one file from {stage_location_url}, " + f"but got {len(get_results)}." + ) return target_path / file_path.name def show_functions(