fix: escape glob special chars in directory paths during stage copy#2804
Open
mdrach wants to merge 2 commits intosnowflakedb:mainfrom
Open
fix: escape glob special chars in directory paths during stage copy#2804mdrach wants to merge 2 commits intosnowflakedb:mainfrom
mdrach wants to merge 2 commits intosnowflakedb:mainfrom
Conversation
Directories with square brackets (e.g., [id], [slug]) failed during recursive stage copy with error 'File doesn't exist: [.../[id]/*]'. The bug occurred because [id]/* was interpreted as a glob pattern matching 'i/*' or 'd/*' instead of the literal '[id]/*' directory. Fix: Use glob.escape() before appending /* to directory paths. This only affects real directories (checked via .is_dir()), so user-provided glob patterns like 'src/[abc]' or '*.py' continue to work correctly. Changes: - manager.py:406,369-372: Add glob.escape() when appending wildcards - test_stage.py: Add 4 tests for brackets and glob pattern preservation
39cd0dd to
538f42a
Compare
A path like '/tmp/campaigns/[id]/' would produce '/tmp/campaigns/[id]//*' after escaping and appending '/*'. Strip trailing slashes first so the result is always clean (e.g. '/tmp/campaigns/[[]id]/*'). Also removes test_stage_put_preserves_user_glob_patterns_with_brackets which re-implemented the logic under test rather than calling StageManager, and adds two new tests: trailing slash alone and trailing slash + brackets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
||
| call_args = mock_execute.call_args[0][0] | ||
| assert "//*" not in call_args, f"Double slash found in: {call_args}" | ||
| assert call_args.endswith(f"{tmp_dir}/* @stageName auto_compress=false parallel=4 overwrite=False") |
Contributor
There was a problem hiding this comment.
The test assertion will fail if tmp_dir contains glob special characters (e.g., [, ], *, ?). The implementation on line 370 of manager.py applies glob.escape() to the path, but this assertion compares against the unescaped tmp_dir.
If TemporaryDirectory() creates a path like /tmp/pytest-[abc]/..., the actual call would contain file:///tmp/pytest-[[]abc]/.../* (escaped), but the assertion checks for /tmp/pytest-[abc]/* (unescaped), causing a test failure.
Fix:
expected_path = glob.escape(tmp_dir) + "/*"
assert call_args.endswith(f"{expected_path} @stageName auto_compress=false parallel=4 overwrite=False")This matches the pattern used correctly in the other tests (lines 1589 and 1689).
Suggested change
| assert call_args.endswith(f"{tmp_dir}/* @stageName auto_compress=false parallel=4 overwrite=False") | |
| expected_path = glob.escape(tmp_dir) + "/*" | |
| assert call_args.endswith(f"{expected_path} @stageName auto_compress=false parallel=4 overwrite=False") |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
Contributor
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.
Directories with square brackets (e.g., [id], [slug]) failed during recursive stage copy with error 'File doesn't exist: [.../[id]/*]'.
The bug occurred because [id]/* was interpreted as a glob pattern matching 'i/' or 'd/' instead of the literal '[id]/*' directory.
Fix: Use glob.escape() before appending /* to directory paths. This only affects real directories (checked via .is_dir()), so user-provided glob patterns like 'src/[abc]' or '*.py' continue to work correctly.
Changes:
Screenshot of symptom

Pre-review checklist
Changes description
Fixed bug that caused literal filepaths with special characters like
[``]to be interpreted as globs.