Skip to content

Comments

Fix snow stage copy --recursive dropping FQN qualifiers#2777

Open
sfc-gh-moczko wants to merge 1 commit intomainfrom
fix/stage-copy-recursive-fqn-2764
Open

Fix snow stage copy --recursive dropping FQN qualifiers#2777
sfc-gh-moczko wants to merge 1 commit intomainfrom
fix/stage-copy-recursive-fqn-2764

Conversation

@sfc-gh-moczko
Copy link
Collaborator

@sfc-gh-moczko sfc-gh-moczko commented Feb 23, 2026

Summary

  • Fixed iter_stage() in StageManager silently 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's ls command returns file names with only the unqualified stage name (e.g., stage/path/file.txt), and iter_stage() passed that directly to build_path(), which reconstructed a new StagePath without the original FQN qualifiers.

Root cause

In StageManager.iter_stage(), the else branch called self.build_path(file["name"]) where file["name"] from ls output contains only the bare stage name. build_pathStagePath.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 ls output by splitting off the unqualified stage name prefix, then join it with stage_path.root_path() which preserves the original FQN from user input.

Test plan

  • Added 5 parametrized test cases to test_copy_get_recursive covering: FQN root (@db.schema.exe), FQN with trailing slash, FQN with subdirectory, FQN with specific file, and schema-qualified (@schema.exe)
  • All 17 recursive copy tests pass (8 existing + 5 new FQN + 4 user stage)
  • Full stage test suite passes (319 tests, 50 snapshots)
  • Verified tests catch regression: reverting the fix causes FQN test cases to fail (GET commands show @exe/... instead of @db.schema.exe/...)

@sfc-gh-moczko sfc-gh-moczko requested a review from a team as a code owner February 23, 2026 19:30
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>
@sfc-gh-moczko sfc-gh-moczko force-pushed the fix/stage-copy-recursive-fqn-2764 branch from 3fc4d22 to 79fc96b Compare February 23, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant