Skip to content

Quote ALTER SCHEMA SET values - #70

Open
jacodegroothydrab wants to merge 4 commits into
datacoves:mainfrom
jacodegroothydrab:fix/schema-comment-quoting
Open

Quote ALTER SCHEMA SET values#70
jacodegroothydrab wants to merge 4 commits into
datacoves:mainfrom
jacodegroothydrab:fix/schema-comment-quoting

Conversation

@jacodegroothydrab

Copy link
Copy Markdown
Contributor

update_schema builds its literal by hand:

new_value = f"'{new_value}'" if isinstance(new_value, str) else new_value

so an apostrophe ends the string early and the rest arrives as bare SQL:

001003 (42000): SQL compilation error: syntax error line 1 at position 39
unexpected 'comment'. on ALTER SCHEMA MY_DB.MY_SCHEMA SET comment = '...

Any schema comment containing an apostrophe fails to apply. CREATE is unaffected — it already renders through props.quote_value. update_schema was the one branch that hand-rolled its quoting; it now uses quote_value too.

quote_value had the mirror-image gap: $$ is a safe delimiter only while the value doesn't contain $$. It now falls back to a single-quoted literal with ' and backslash doubled in that case.

4 regression tests, all four failing against the current code.

@jacodegroothydrab jacodegroothydrab changed the title fix(schema): quote ALTER SCHEMA SET values instead of hand-rolling the literal Quote ALTER SCHEMA SET values instead Aug 26, 2026
@noel

noel commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

snowcap/props.py:36: The fallback for values containing $$ produces a single-quoted literal, but it only escapes apostrophes and backslashes. Actual control characters such as newlines remain unescaped, although Snowflake requires escape sequences inside single-quoted literals. This regresses multiline values that previously worked with dollar quoting.

Please escape control characters such as \n, \r, and \t after escaping backslashes, and add a regression test covering a value containing both $$ and a newline.

Also, please remove or substantially shorten the explanatory comment blocks in snowcap/lifecycle.py and snowcap/props.py; the code and regression tests already document the behavior clearly.

@jacodegroothydrab jacodegroothydrab changed the title Quote ALTER SCHEMA SET values instead Quote ALTER SCHEMA SET values Aug 27, 2026
@jacodegroothydrab

jacodegroothydrab commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

I have addressed your feedback

  • Deleted the comment. Duplicate comment risks confusing LLMs if they diverge in the future.
  • Escaped control characters
  • Add regression tests

Please let me know if you require further changes.

@noel

noel commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

snowcap/props.py:35: The fallback now escapes newline, carriage return, and tab, but still emits backspace, form feed, NUL, and other C0 control characters directly into the SQL literal. Snowflake provides escape sequences for these characters, so the fallback is not yet safe for every string accepted by quote_value.

Rather than extending the replacement chain one character at a time, please use the existing json standard-library import to escape control characters, strip its surrounding quotes, and then double apostrophes—for example:

escaped = json.dumps(str(value), ensure_ascii=False)[1:-1].replace("'", "''")

Please add regression coverage containing $$ with \b, \f, and NUL. See Snowflake’s string-literal documentation.

@jacodegroothydrab

Copy link
Copy Markdown
Contributor Author

Done — the fallback now uses json.dumps(str(value), ensure_ascii=False)[1:-1].replace("'", "''"), so the whole C0 range is escaped rather than the four characters the chain happened to list. Added regression tests for $$ with \b/\f and with NUL (json emits \u0000, which Snowflake accepts).

jacodegroothydrab and others added 4 commits August 28, 2026 13:39
…e literal

update_schema built its SQL literal with a bare f"'{new_value}'", so an
apostrophe in the value ended the string early and the rest arrived as bare SQL:

  001003 (42000): SQL compilation error: syntax error line 1 at position 39
  unexpected 'comment'. on ALTER SCHEMA MY_DB.MY_SCHEMA SET comment = '...

Any schema comment containing an apostrophe therefore fails to apply. Only the
ALTER path is affected -- CREATE already renders through props.quote_value,
which dollar-quotes and needs no escaping. update_schema was the one branch
that hand-rolled its quoting; it now goes through quote_value too.

quote_value itself had the mirror-image gap: $$ is a safe delimiter only while
the value does not contain $$. It now falls back to a single-quoted literal
with ' and backslash doubled in that case, so a value cannot break out by
either route.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Snowflake needs escape sequences, not raw control characters, inside a
single-quoted literal, so the $$ fallback regressed multiline values.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The hand-rolled replacement chain covered newline, carriage return and
tab but left backspace, form feed, NUL and the rest of the C0 range raw
in the single-quoted literal. json.dumps escapes the whole range using
the same backslash syntax Snowflake accepts, so the fallback now only
has to double apostrophes on top of it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jacodegroothydrab
jacodegroothydrab force-pushed the fix/schema-comment-quoting branch from 4c599b4 to 403ffa7 Compare August 28, 2026 12:40
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.

2 participants