Repository navigation
fix: escape backslashes in description comments - #1709
Open
maharanay22 wants to merge 1 commit into
Open
maharanay22 wants to merge 1 commit into
maharanay22 wants to merge 1 commit into
Conversation
maharanay22
requested review from
jprakash-db,
saishreeeee and
sd-db
as code owners
October 8, 2026 22:35
Databricks reads a backslash in a string literal as an escape, so a description like `^\d+` was stored as `^d+`, `C:\tmp` picked up a tab, and a trailing backslash escaped the closing quote and broke the statement. Only `get_create_sql_comment` escaped backslashes. Move its escaping into a shared `escape_comment` macro, use it at every site that writes a description into a COMMENT literal (relation comment clause, COMMENT ON TABLE/VIEW/COLUMN, view column list, seed column list), and apply the same escaping in `DatabricksColumn.render_for_create`. Signed-off-by: Maha Rana Yadavalli <271375718+maharanay22@users.noreply.github.com>
maharanay22
force-pushed
the
fix-comment-backslash-escaping
branch
from
October 8, 2026 22:35
50e700a to
1c14e9f
Compare
This branch has not been deployed
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.
No existing issue (I searched open and closed issues and PRs).
Description
Databricks reads
\in a string literal as an escape character. Descriptions are written intoCOMMENT '...'literals with only'escaped, so a description of^\d+is stored as^d+,C:\tmppicks up a tab, and a description ending in\turns the closing quote into\', which leaves the literal unterminated and the statement fails to parse. Because the stored comment never matches the YAML, comment diffing also keeps re-applying it.#1613 fixed this in
get_create_sql_commentonly. This PR moves that escaping (backslash first, then quote) into a sharedescape_commentmacro and uses it at every other site that writes a description into a comment literal:databricks__comment_clause,alter_relation_comment_sql,databricks__alter_column_comment,alter_column_comments,get_column_comment_sql(views) and the seed column list.DatabricksColumn.render_for_creategets the same escaping. Output for descriptions without backslashes is unchanged, andget_create_sql_commentrenders exactly as before.Unit tests assert the exact SQL for a
\dregex, a Windows path, a trailing backslash, and a description with both\and'at each site. 13 of the new tests fail onmainwith the wrong or unterminated literal; all pass with this change. I also rendered the macros throughdbt run-operation(dbt 1.12.5):Bob\'s ^\d in C:\tmp, trailing \now renders asIS 'Bob\\'s ^\d in C:\tmp, trailing \'instead ofIS 'Bob\'s ^\d in C:\tmp, trailing \'.Checklist
CHANGELOG.mdand added information about my change to the "dbt-databricks next" section.dbt-databricks-pr-readyproject skill for this PR and addressed its merge-readiness feedback