Skip to content

fix(spanner-sqlalchemy): add WHERE 1=1 to unqualified DELETE and UPDATE - #19024

Merged
olavloite merged 2 commits into
mainfrom
spanner-sql-alchemy-where-1is1
Nov 10, 2026
Merged

olavloite merged 2 commits into
mainfrom
spanner-sql-alchemy-where-1is1

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Cloud Spanner requires a WHERE clause for all DELETE and UPDATE statements to prevent accidental full-table modifications.

Previously, unqualified statements relied on the low-level DB-API driver to rewrite SQL strings and append "WHERE 1=1". The dialect now generates this clause directly during query compilation. This ensures statements with THEN RETURN clauses have valid syntax and prepares the library for removing automatic SQL rewriting from the DB-API driver.

@olavloite
olavloite requested a review from a team as a code owner November 9, 2026 16:16

@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 implements automatic injection of a 'WHERE 1=1' clause for unqualified DELETE and UPDATE statements to satisfy Cloud Spanner requirements, along with a safety fix for accessing column dialect options and comprehensive unit tests. The feedback recommends extracting the duplicated WHERE clause injection logic in visit_delete and visit_update into a reusable helper method to adhere to DRY principles.

Cloud Spanner requires a WHERE clause for all DELETE and UPDATE statements
to prevent accidental full-table modifications.

Previously, unqualified statements relied on the low-level DB-API driver to
rewrite SQL strings and append "WHERE 1=1". The dialect now generates this
clause directly during query compilation. This ensures statements with
THEN RETURN clauses have valid syntax and prepares the library for removing
automatic SQL rewriting from the DB-API driver.
@olavloite
olavloite force-pushed the spanner-sql-alchemy-where-1is1 branch from 213cdbd to 62ecc6d Compare November 9, 2026 16:34
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 ensures that unqualified DELETE and UPDATE statements automatically append a dummy WHERE 1=1 clause to satisfy Cloud Spanner's requirements, and safely handles columns without dialect options in the returning clause. Comprehensive unit tests are added to verify these behaviors. The reviewer recommends updating self.statement when modifying the statement during compilation in both visit_delete and visit_update to prevent potential inconsistencies in post-compilation steps.

@olavloite
olavloite enabled auto-merge (squash) November 10, 2026 16:19
@olavloite
olavloite merged commit 5a2b34e into main Nov 10, 2026
56 of 57 checks passed
@olavloite
olavloite deleted the spanner-sql-alchemy-where-1is1 branch November 10, 2026 16:21
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