Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 13 commits into from

Conversation

IlyaFaer
Copy link
Contributor

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 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 google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 24, 2020
@IlyaFaer
Copy link
Contributor Author

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

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

@c24t c24t left a comment

Choose a reason for hiding this comment

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

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


def __do_execute_update(self, transaction, sql, params, param_types=None):
sql = ensure_where_clause(sql)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

None yet

3 participants