SNOW-3718303: Correctly escape special characters in comment/collate/subfield/flatten SQL#4271
Merged
Merged
Conversation
…subfield/flatten SQL Values passed to DataFrame comment (create_or_replace_view / dynamic table / save_as_table), Column.collate, Column.__getitem__ subfield keys, and DataFrame/Session.flatten PATH were concatenated into SQL string literals without escaping backslashes (and, for collate/subfield/flatten, single quotes), so values containing those characters produced invalid SQL. Adds a dedicated escape_quotes_and_backslashes helper applied only at those sinks; the shared escape_single_quotes is unchanged so other callers are unaffected. Column.collate keeps its pre-quoted-spec handling so legitimate specs behave identically. Adds unit and integ tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4271 +/- ##
=======================================
Coverage 95.52% 95.52%
=======================================
Files 171 171
Lines 44305 44358 +53
Branches 7565 7577 +12
=======================================
+ Hits 42322 42375 +53
Misses 1221 1221
Partials 762 762 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… quotes Column.__getitem__ historically emitted the VARIANT/OBJECT subfield key verbatim between single quotes, so callers were expected to double their own single quotes (see test_column_suite.py::test_subfield). Unconditionally running the key through escape_quotes_and_backslashes double-escaped those already-doubled quotes, changing the resolved key and breaking existing callers. Add escape_subfield_key(): if every single quote in the key is already doubled, preserve them as-is (escaping only backslashes so \t/\n stay literal); otherwise fully escape. This keeps the historical contract byte-identical, makes a raw apostrophe work too, and still neutralizes any key that would otherwise break out of the literal. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sfc-gh-yuwang
approved these changes
Jul 1, 2026
sfc-gh-joshi
approved these changes
Jul 1, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-3718303, SNOW-3718304, SNOW-3718305, SNOW-3718306
Values passed to DataFrame comment (create_or_replace_view / dynamic table / save_as_table), Column.collate, Column.getitem subfield keys, and DataFrame/Session.flatten PATH were concatenated into SQL string literals without escaping backslashes (and, for collate/subfield/flatten, single quotes), so values containing those characters produced invalid SQL. Adds a dedicated escape_quotes_and_backslashes helper applied only at those sinks; the shared escape_single_quotes is unchanged so other callers are unaffected. Column.collate keeps its pre-quoted-spec handling so legitimate specs behave identically. Adds unit and integ tests.
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
Please write a short description of how your code change solves the related issue.