GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |
GeezerVison is showing github.com — fix(spanner): support parameters and preserve safety in partitioned DML by olavloite · Pull Request #19035 · googleapis/google-cloud-python Conversation
Contributor
Partitioned DML executed through the Cloud Spanner DB-API driver previously failed whenever query parameters were used. The driver passed raw positional placeholders and parameter lists directly to the database rather than converting them into the named parameters and data types expected by Cloud Spanner. Additionally, statement parsing historically mutated SQL statements in place to automatically append a dummy "WHERE 1=1" clause to update and delete statements. Injecting this dummy clause into Partitioned DML is dangerous because Partitioned DML is non-atomic, irreversible, and cannot be rolled back. Bypassing Cloud Spanner's requirement for an explicit WHERE clause risks unintended full-table modifications. This change addresses these issues by:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code ReviewThis pull request refactors the Spanner DB-API to prevent dummy WHERE clauses from being automatically added to partitioned DML statements. The logic for adding dummy WHERE clauses to UPDATE and DELETE statements is moved from the classification phase in parse_utils.py to specific cursor execution paths, and comprehensive tests are added to verify the new behavior. The review feedback suggests using the NamedTuple._replace() method in _ensure_where_clause to update the ParsedStatement and Statement objects more cleanly and safely.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Partitioned DML executed through the Cloud Spanner DB-API driver previously failed whenever query parameters were used. The driver passed raw positional placeholders and parameter lists directly to the database rather than converting them into the named parameters and data types expected by Cloud Spanner. Additionally, statement parsing historically mutated SQL statements in place to automatically append a dummy "WHERE 1=1" clause to update and delete statements. Injecting this dummy clause into Partitioned DML is dangerous because Partitioned DML is non-atomic, irreversible, and cannot be rolled back. Bypassing Cloud Spanner's requirement for an explicit WHERE clause risks unintended full-table modifications. This change addresses these issues by: - Properly translating and passing query parameters and their data types during Partitioned DML execution. - Making statement parsing pure and side-effect free so SQL statements are no longer mutated during classification. - Ensuring Partitioned DML statements never receive an automatic dummy WHERE clause, keeping Cloud Spanner's safety checks intact. - Guarding Partitioned DML mode so that statements executed inside an explicit transaction always run as atomic transactional DML. - Retaining automatic dummy WHERE clause injection exclusively for transactional and batch DML to preserve full backwards compatibility for existing applications.
olavloite
force-pushed
the
spanner-preserve-params-in-pdml
branch
from
47b8ba8 to
218d44b
Compare
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code ReviewThis pull request refactors how dummy WHERE clauses are added to unqualified UPDATE and DELETE statements in the Spanner DB API. Instead of automatically appending 'WHERE 1=1' during statement classification in parse_utils.py, the logic is moved to the cursor execution level via a new _ensure_where_clause helper. This ensures that partitioned DML statements do not receive a dummy WHERE clause, while transactional DML, batch DML, and executemany statements still do. Comprehensive unit and mock server tests have been added to verify these behaviors, including idempotency during transaction retries. I have no further feedback to provide.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThis branch has not been deployedNo deployments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reviewers1 more reviewerAt least 1 approving review is required to merge this pull request. Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. | |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |