FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: avoid adding a dummy WHERE clause into UPDATE/DELETE queries by IlyaFaer · Pull Request #464 · googleapis/python-spanner-django · GitHub

This repository was archived by the owner on Jun 8, 2026. It is now read-only.

feat: avoid adding a dummy WHERE clause into UPDATE/DELETE queries - #464

Closed
IlyaFaer wants to merge 13 commits into
googleapis:masterfrom
MaxxleLLC:cursor_refactor
Closed

IlyaFaer wants to merge 13 commits into
googleapis:masterfrom
MaxxleLLC:cursor_refactor

Conversation

Copy link
Copy Markdown

Adding a WHERE clause into user's query doesn't seem to be a good practise in the first place. More than that Spanner requires WHERE clause presence in UPDATE and DELETE queries (see the docs). Adding a dummy WHERE clause silently overrides the original Spanner requirement, and actually leads to what the requirement prevents: accidental updating/deleting every row.

It doesn't look correct, let's raise an error in case of no WHERE clause detected - it'll warn user that the thing he's trying to do can be dangerous. If he's okay with it, he can add WHERE true by his own hands.

IlyaFaer added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: spanner Issues related to the googleapis/python-spanner-django API. labels Aug 24, 2020
google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 24, 2020

Copy link
Copy Markdown
Author

This PR is based on changes from the previous PR, and should be merged after merging the previous one.

IlyaFaer marked this pull request as ready for review August 24, 2020 12:05
IlyaFaer requested a review from c24t August 24, 2020 12:06

c24t 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also sounds like a sensible change. I'll review again after #462, #463 are merged.

Comment thread spanner_dbapi/cursor.py
self._connection.in_transaction(self.__do_execute_update, sql, params)

def __do_execute_update(self, transaction, sql, params, param_types=None):
sql = ensure_where_clause(sql)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I also realized that it's not very okay to do the check here, as __do_execute_update() will be sent to Database.run_in_transaction(), and then to Session.run_in_transaction() as func arg. This last method will start a transaction (if needed) and only then it'll run __do_execute_update() (and the check). We better run the check before starting anything. The check call moved to line 99

IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 4, 2020
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 4, 2020
IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 9, 2020
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 9, 2020
IlyaFaer closed this Sep 9, 2020
IlyaFaer reopened this Sep 9, 2020
IlyaFaer closed this Sep 9, 2020
IlyaFaer deleted the cursor_refactor branch November 20, 2020 08:21
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/python-spanner-django API. cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL