Skip to content

fix(django-google-spanner): escape backslashes in quote_value#17537

Open
saddamr3e wants to merge 1 commit into
googleapis:mainfrom
saddamr3e:spanner-quote-value-escape
Open

fix(django-google-spanner): escape backslashes in quote_value#17537
saddamr3e wants to merge 1 commit into
googleapis:mainfrom
saddamr3e:spanner-quote-value-escape

Conversation

@saddamr3e

Copy link
Copy Markdown
Contributor

DatabaseSchemaEditor.quote_value inlines string values into DDL (Spanner doesn't accept bind parameters in those positions) and escapes them with ANSI quote doubling. Cloud Spanner runs GoogleSQL, which escapes a quote with a backslash and treats the backslash itself as an escape character, so doubling is the wrong convention here. A plain apostrophe such as a default of O'Brien renders as 'O''Brien' and fails to parse, and a value that contains a backslash escapes the closing quote and runs off the end of the literal. With a crafted default like \' OR 1=1 -- the output becomes '\'' OR 1=1 -- ', where the \' is an escaped quote and the following quote closes the string, leaving OR 1=1 as live SQL. I noticed it because the generated-column and db_default paths a few lines up in the same file already escape the GoogleSQL way, while quote_value (and prepare_default, which calls it) still doubled. The change moves quote_value to the same backslash escaping so the value stays inside its literal.

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@saddamr3e saddamr3e requested a review from a team as a code owner June 23, 2026 10:06

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the quote_value method in DatabaseSchemaEditor to correctly escape string values for Cloud Spanner (GoogleSQL) by using backslashes instead of doubling single quotes. It also adds corresponding unit tests to verify that backslashes and single quotes are properly escaped. There are no review comments, so I have no feedback to provide.

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