Skip to content

Commit 5e8ca94

Browse files
authored
fix: allow setting connection.read_only to same value (#1247)
Setting the read_only value of a connection to the same value as the current value should be allowed during a transaction, as it does not change anything. SQLAlchemy regularly does this if engine options have been specified. Fixes googleapis/python-spanner-sqlalchemy#493
1 parent eeb7836 commit 5e8ca94

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

google/cloud/spanner_dbapi/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def read_only(self, value):
239239
Args:
240240
value (bool): True for ReadOnly mode, False for ReadWrite.
241241
"""
242-
if self._spanner_transaction_started:
242+
if self._read_only != value and self._spanner_transaction_started:
243243
raise ValueError(
244244
"Connection read/write mode can't be changed while a transaction is in progress. "
245245
"Commit or rollback the current transaction and try again."

tests/unit/spanner_dbapi/test_connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ def test_read_only_connection(self):
138138
):
139139
connection.read_only = False
140140

141+
# Verify that we can set the value to the same value as it already has.
142+
connection.read_only = True
143+
self.assertTrue(connection.read_only)
144+
141145
connection._spanner_transaction_started = False
142146
connection.read_only = False
143147
self.assertFalse(connection.read_only)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy