Repository navigation
fix(spanner-sqlalchemy): add WHERE 1=1 to unqualified DELETE and UPDATE - #19024
Conversation
There was a problem hiding this comment.
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.
213cdbd to
62ecc6d
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
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.