Skip to content

fix(sqlalchemy-spanner): quote DDL identifiers in CREATE TABLE - #19238

Open
olavloite wants to merge 3 commits into
mainfrom
spanner-sqlalchemy-quote-identifiers-in-create-table
Open

olavloite wants to merge 3 commits into
mainfrom
spanner-sqlalchemy-quote-identifiers-in-create-table

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Primary key column names and interleaved parent table names in generated CREATE TABLE statements were previously inserted verbatim without identifier quoting. As a result, reserved keywords or special characters could produce invalid DDL, and untrusted names could break out into additional SQL or DDL statements.

This change:

  • Quotes primary key column names consistently with the table's column definitions.
  • Quotes interleaved parent table names, formats table objects cleanly (including schema-qualified parents), and rejects invalid non-string, non-table values.
  • Adds unit tests covering quoting, interleaved table options, invalid input handling, and DDL injection prevention, along with a skipped test case for escaped backticks, backslashes, and newlines pending identifier escaping support.

Primary key column names and interleaved parent table names in generated
CREATE TABLE statements were previously inserted verbatim without identifier
quoting. As a result, reserved keywords or special characters could produce
invalid DDL, and untrusted names could break out into additional SQL or DDL
statements.

This change:
- Quotes primary key column names consistently with the table's column
  definitions.
- Quotes interleaved parent table names, formats table objects cleanly
  (including schema-qualified parents), and rejects invalid non-string,
  non-table values.
- Adds unit tests covering quoting, interleaved table options, invalid input
  handling, and DDL injection prevention, along with a skipped test case for
  escaped backticks, backslashes, and newlines pending identifier escaping
  support.
@olavloite
olavloite requested a review from a team as a code owner November 26, 2026 10:55

@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 enhances the security and robustness of table creation in the Spanner SQLAlchemy dialect. It updates the post_create_table method to properly quote primary key columns and parent tables in INTERLEAVE IN PARENT clauses, mitigating potential DDL injection vulnerabilities. It also introduces type annotations and stricter type validation for the spanner_interleave_in parameter. Furthermore, a comprehensive set of unit tests has been added to verify quoting behavior, type safety, and injection prevention. I have no additional feedback to provide as the implementation is clean and well-tested.

This branch has not been deployed

No deployments
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