Skip to content

Commit a214885

Browse files
fix: allow setting staleness to same value in tx (#1253)
* fix: allow setting staleness to same value in tx Repeatedly setting the staleness property of a connection in a transaction to the same value caused an error. This made it harder to use this property in SQLAlchemy. Updates googleapis/python-spanner-sqlalchemy#495 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Revert "🦉 Updates from OwlBot post-processor" This reverts commit 282a982. --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7df93ca commit a214885

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

google/cloud/spanner_dbapi/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def staleness(self, value):
277277
Args:
278278
value (dict): Staleness type and value.
279279
"""
280-
if self._spanner_transaction_started:
280+
if self._spanner_transaction_started and value != self._staleness:
281281
raise ValueError(
282282
"`staleness` option can't be changed while a transaction is in progress. "
283283
"Commit or rollback the current transaction and try again."

tests/unit/spanner_dbapi/test_connection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,20 @@ def test_staleness_inside_transaction(self):
669669
with self.assertRaises(ValueError):
670670
connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)}
671671

672+
def test_staleness_inside_transaction_same_value(self):
673+
"""
674+
Verify that setting `staleness` to the same value in a transaction is allowed.
675+
"""
676+
connection = self._make_connection()
677+
connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)}
678+
connection._spanner_transaction_started = True
679+
connection._transaction = mock.Mock()
680+
681+
connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)}
682+
self.assertEqual(
683+
connection.staleness, {"read_timestamp": datetime.datetime(2021, 9, 21)}
684+
)
685+
672686
def test_staleness_multi_use(self):
673687
"""
674688
Check that `staleness` option is correctly

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