GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(db_api): add an ability to set ReadOnly/ReadWrite connection mode by IlyaFaer · Pull Request #475 · googleapis/python-spanner

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

Conversation

@IlyaFaer

@IlyaFaer IlyaFaer commented Aug 2, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Proposal for the user's question: googleapis/python-spanner-sqlalchemy#97
Will require small changes in SQLAlchemy dialect as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
IlyaFaer
feat(db_api): add an ability to set ReadOnly/ReadWrite connection mode
4d7684e
@IlyaFaer IlyaFaer added api: spanner Issues related to the googleapis/python-spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Aug 2, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 2, 2021
IlyaFaer
IlyaFaer commented Aug 2, 2021
View reviewed changes
Comment thread google/cloud/spanner_dbapi/connection.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

IlyaFaer added 3 commits August 2, 2021 12:49
IlyaFaer
update the error message
990fe3e
IlyaFaer
update another error message
2381c6d
IlyaFaer
don't check error messages with regexes
9cec921
@IlyaFaer
IlyaFaer marked this pull request as ready for review August 3, 2021 07:52
@IlyaFaer
IlyaFaer requested review from a team and larkee August 3, 2021 07:52
olavloite
olavloite suggested changes Aug 4, 2021
View reviewed changes
Comment thread google/cloud/spanner_v1/transaction.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/system/test_system_dbapi.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/system/test_system_dbapi.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

IlyaFaer added 3 commits August 5, 2021 11:02
IlyaFaer
don't commit/rollback ReadOnly transactions
d6783b8
IlyaFaer
clear the transaction
131a6fc
IlyaFaer
add read-only transactions data visibility test
e1a3db2
olavloite
olavloite reviewed Aug 5, 2021
View reviewed changes
Comment thread google/cloud/spanner_dbapi/connection.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

olavloite
olavloite reviewed Aug 5, 2021
View reviewed changes
Comment thread google/cloud/spanner_dbapi/connection.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/transaction.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/transaction.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Ilya Gurov and others added 5 commits August 5, 2021 22:11
Ilya Gurov @olavloite
Apply suggestions from code review
4bd65e7
Co-authored-by: Knut Olav Løite <[email protected]>
IlyaFaer
add conditions for edge cases
4186609
IlyaFaer
Merge branch 'read_only_transactions' of https://github.com/q-logic/p…
0f3e716
…ython-spanner into read_only_transactions
IlyaFaer
don't calc checksum for read-only transactions
8332d49
Ilya Gurov
Merge branch 'master' into read_only_transactions
61fc8ad
olavloite
olavloite reviewed Aug 9, 2021
View reviewed changes
Comment thread google/cloud/spanner_dbapi/connection.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_dbapi/cursor.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

larkee
larkee suggested changes Aug 9, 2021
View reviewed changes

@larkee larkee left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Read-only transaction in the Python client are represented by the Snapshot class.

Please do not modify transaction.py. Use Snapshot instead.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
IlyaFaer added 2 commits August 10, 2021 11:05
IlyaFaer
use Snapshot for reads
0be92af
IlyaFaer
update docstrings
3a72694
@IlyaFaer

IlyaFaer commented Aug 10, 2021

Copy link
Copy Markdown
Author

@larkee, hm, okay. If we want to use the Snapshot() class, we probably could re-use the existing method for single-use reads. Let me know if you think it's better to use a snapshot as a transaction for several sequential reads.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

IlyaFaer
Merge branch 'master' into read_only_transactions
00887ff
@larkee

larkee commented Aug 11, 2021

Copy link
Copy Markdown
Contributor

@larkee, hm, okay. If we want to use the Snapshot() class, we probably could re-use the existing method for single-use reads. Let me know if you think it's better to use a snapshot as a transaction for several sequential reads.

By default, a snapshot is a single-use read-only transaction so it would only be valid for one read operation. However, there is an option make a multi-use snapshot in which all reads are from the same snapshot of data i.e. data is consistent.

Multi-use snapshot example: https://cloud.google.com/spanner/docs/transactions#ro_transaction_example
Single-use snapshot example: https://cloud.google.com/spanner/docs/reads#single_read_methods

With this in mind, I think using multi_use snapshots should only be used when read_only=True and AUTOCOMMIT=False. WDYT?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@olavloite

olavloite commented Aug 11, 2021

Copy link
Copy Markdown
Contributor

With this in mind, I think using multi_use snapshots should only be used when read_only=True and AUTOCOMMIT=False. WDYT?

Yes, that is the intention here. So the implementation should roughly be:

  1. read_only=True and auto_commit=False: Use multi_use snapshots and only allow queries/reads. Calling commit() or rollback() should close the current multi-use snapshot, and the next statement that is executed should create a new multi-use snapshot.
  2. auto_commit=True (and regardless of the state of read_only): Always use single-use snapshots for queries/reads.
larkee reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

IlyaFaer
refactor
ac8c4b2
@IlyaFaer

IlyaFaer commented Sep 14, 2021

Copy link
Copy Markdown
Author

@skuruppu, of course, it's not. I don't want to sound boring, but I can't see why you both think it's that performance influencing. We don't calculate checksums in read_only - the ifs are already added (8332d49). As for retrying read_only, well, read_only transactions don't fail with Aborted, so they're not gonna be retried anyway. Thus, I don't see why these changes should be urgent and delay other fixes...

Anyway it's pushed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@olavloite

olavloite commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

... but I can't see why you both think it's that performance influencing. We don't calculate checksums in read_only - the ifs are already added (8332d49).

Sorry, that was my fault. I didn't realize that you had already created that change, as the comment that you referenced above didn't say anything about that.

... Thus, I don't see why these changes should be urgent and delay other fixes...

In my opinion, the current implementation would have been slightly confusing for a potential new developer. The retry mechanism is not needed for read-only transactions. I think that it is better that it is completely clear in the code to prevent anyone from accidentally re-enabling it in the future. (This last commit for example has also removed an unnecessary test case that tested the retry mechanism for a query in autocommit mode; a situation that could not happen, but still was part of the code base.)

Anyways, I'm happy enough with this as-is, but we should add a system test ASAP to actually show that it is working as intended. If @skuruppu and/or @larkee are OK with that, then we could do that in a separate PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skuruppu

skuruppu commented Sep 15, 2021

Copy link
Copy Markdown
Contributor

Ultimately @larkee needs to approve this as the code owner so please do add any tests that they ask for before merging.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@larkee

larkee commented Sep 15, 2021

Copy link
Copy Markdown
Contributor

@IlyaFaer I second what @olavloite said. The refactor is less about performance (since it should be roughly equivalent) but is more about readability and reducing confusion for new developers.

However, if you create a tracking issue for the refactor work, I will approve and merge this PR 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@IlyaFaer

IlyaFaer commented Sep 15, 2021

Copy link
Copy Markdown
Author

I think all comments are already processed.

I've pushed changes with adding if statements into fetch methods to avoid retrying read_only transactions, etc. (see MaxxleLLC@ac8c4b2). So, I don't think any refactoring left here.

I also returned back that deleted-by-merge-of-another-commit system test. It checks that UPDATE operation will cause an error, while SELECT will work fine.

I think it's worth adding a unit test, which'll check that read_only transactions are not retried on Aborted exception. Otherwise, I think we don't have anything for a separate issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

larkee
larkee approved these changes Sep 16, 2021
View reviewed changes
larkee and others added 3 commits September 16, 2021 15:14
@larkee
Merge branch 'main' into read_only_transactions
ae9cd00
IlyaFaer
add unit test to check that read-only transactions are not retried
6973748
IlyaFaer
Merge branch 'read_only_transactions' of https://github.com/q-logic/p…
5dab169
…ython-spanner into read_only_transactions
@IlyaFaer IlyaFaer mentioned this pull request Sep 21, 2021
feat(db_api): support stale reads #584
Merged
@skuruppu
Merge branch 'main' into read_only_transactions
5761c30
olavloite
olavloite approved these changes Sep 22, 2021
View reviewed changes
@IlyaFaer IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 22, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 22, 2021
@IlyaFaer IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 27, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 27, 2021
@skuruppu
Merge branch 'main' into read_only_transactions
afeb585
@skuruppu skuruppu added the automerge Merge the pull request once unit tests and other checks pass. label Oct 5, 2021
@gcf-merge-on-green

gcf-merge-on-green Bot commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gcf-merge-on-green gcf-merge-on-green Bot removed the automerge Merge the pull request once unit tests and other checks pass. label Oct 5, 2021
@IlyaFaer IlyaFaer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 5, 2021
Ilya Gurov
Merge branch 'main' into read_only_transactions
1ccb387
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 5, 2021
@IlyaFaer

IlyaFaer commented Oct 5, 2021

Copy link
Copy Markdown
Author

Looking at automerge label set by googler, I suppose it's not a problem if I'll merge it by myself (while tests are green and there are no changes in the main branch).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@IlyaFaer
IlyaFaer merged commit cd3b950 into googleapis:main Oct 5, 2021
@IlyaFaer
IlyaFaer deleted the read_only_transactions branch October 5, 2021 20:59
asthamohta pushed a commit to asthamohta/python-spanner that referenced this pull request Dec 24, 2021
Ilya Gurov @asthamohta
feat(db_api): add an ability to set ReadOnly/ReadWrite connection mode (
8c7c351
googleapis#475)
This was referenced Mar 31, 2026
feat(dbapi): wire timeout parameter through to execute_sql in cursor and connection googleapis/google-cloud-python#16492
Open
feat(dbapi): wire timeout parameter through Connection to execute_sql #1535
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@olavloite olavloite olavloite approved these changes
@larkee larkee larkee approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: spanner Issues related to the googleapis/python-spanner 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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@IlyaFaer @larkee @olavloite @skuruppu @yoshi-kokoro
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 01402775 — 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.