Fix snow stage copy --recursive dropping FQN qualifiers#2777
Open
sfc-gh-moczko wants to merge 1 commit intomainfrom
Open
Fix snow stage copy --recursive dropping FQN qualifiers#2777sfc-gh-moczko wants to merge 1 commit intomainfrom
snow stage copy --recursive dropping FQN qualifiers#2777sfc-gh-moczko wants to merge 1 commit intomainfrom
Conversation
iter_stage() was reconstructing file paths from Snowflake ls output, which only contains the unqualified stage name. This caused GET commands to resolve against the connection default database instead of the database specified in the FQN. Now preserves the original stage_path FQN by using root_path() and joining only the relative file path. Fixes SNOW-3074550 .... Generated with [Cortex Code](https://docs.snowflake.com/user-guide/snowflake-cortex/cortex-agents) Co-Authored-By: Cortex Code <noreply@snowflake.com>
3fc4d22 to
79fc96b
Compare
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.
Summary
iter_stage()inStageManagersilently dropping database and schema qualifiers from fully-qualified stage names during recursive copy, causing GET commands to resolve against the connection's default database instead of the one specified in the FQN.Problem
When running
snow stage copy @db.schema.stage/path/ ./local --recursive, the generated GET commands would use@stage/...instead of@db.schema.stage/.... This happened because Snowflake'slscommand returns file names with only the unqualified stage name (e.g.,stage/path/file.txt), anditer_stage()passed that directly tobuild_path(), which reconstructed a newStagePathwithout the original FQN qualifiers.Root cause
In
StageManager.iter_stage(), theelsebranch calledself.build_path(file["name"])wherefile["name"]fromlsoutput contains only the bare stage name.build_path→StagePath.from_stage_str()parsed this as a new unqualified stage, discarding the database/schema from the original user input.Fix
Extract the relative file path from
lsoutput by splitting off the unqualified stage name prefix, then join it withstage_path.root_path()which preserves the original FQN from user input.Test plan
test_copy_get_recursivecovering: FQN root (@db.schema.exe), FQN with trailing slash, FQN with subdirectory, FQN with specific file, and schema-qualified (@schema.exe)@exe/...instead of@db.schema.exe/...)