Repository navigation
chore(spanner-django): add WHERE 1=1 to unqualified DELETE and UPDATE - #19033
Merged
Merged
Conversation
Cloud Spanner requires a WHERE clause for all DELETE and UPDATE statements to prevent accidental table-wide data modifications. Previously, unqualified queries and schema migration backfills relied on the low-level DB-API driver to rewrite SQL strings and append "WHERE 1=1". The Django backend now generates this clause directly during query compilation and migration execution. Ensuring that Django generates compliant SQL on its own allows us to safely remove automatic SQL string rewriting from the DB-API driver in a future release without breaking Django applications.
Contributor
There was a problem hiding this comment.
Code Review
This pull request ensures that unqualified UPDATE and DELETE statements automatically append a dummy WHERE 1=1 clause in the Django Spanner backend. This is achieved by overriding the as_sql method in SQLDeleteCompiler and SQLUpdateCompiler, updating the schema editor's add_field method, and refining the add_dummy_where utility to handle edge cases safely. Extensive unit and mock server tests have been added to validate this behavior. The reviewer suggested using SQLGlotIR to safely wrap and modify SQL queries instead of manually parsing and manipulating the SQL string to avoid potential parsing issues.
sakthivelmanii
approved these changes
Nov 10, 2026
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.
Cloud Spanner requires a WHERE clause for all DELETE and UPDATE statements to prevent accidental table-wide data modifications.
Previously, unqualified queries and schema migration backfills relied on the low-level DB-API driver to rewrite SQL strings and append "WHERE 1=1". The Django backend now generates this clause directly during query compilation and migration execution.
Ensuring that Django generates compliant SQL on its own allows us to safely remove automatic SQL string rewriting from the DB-API driver in a future release without breaking Django applications.
BEGIN_COMMIT_OVERRIDE
fix(spanner-django): add WHERE 1=1 to unqualified DELETE and UPDATE
END_COMMIT_OVERRIDE