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

fix: allow setting staleness to same value in tx #1253

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/cloud/spanner_dbapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def staleness(self, value):
Args:
value (dict): Staleness type and value.
"""
if self._spanner_transaction_started:
if self._spanner_transaction_started and value != self._staleness:
raise ValueError(
"`staleness` option can't be changed while a transaction is in progress. "
"Commit or rollback the current transaction and try again."
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/spanner_dbapi/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,20 @@ def test_staleness_inside_transaction(self):
with self.assertRaises(ValueError):
connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)}

def test_staleness_inside_transaction_same_value(self):
"""
Verify that setting `staleness` to the same value in a transaction is allowed.
"""
connection = self._make_connection()
connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)}
connection._spanner_transaction_started = True
connection._transaction = mock.Mock()

connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)}
self.assertEqual(
connection.staleness, {"read_timestamp": datetime.datetime(2021, 9, 21)}
)

def test_staleness_multi_use(self):
"""
Check that `staleness` option is correctly
Expand Down
Loading