Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 974ee92

Browse filesBrowse files
feat(spanner): exporting transaction._rolled_back as transaction.rolled_back (#16)
Co-authored-by: larkee <31196561+larkee@users.noreply.github.com>
1 parent 74577c7 commit 974ee92
Copy full SHA for 974ee92

File tree

Expand file treeCollapse file tree

6 files changed

+18
-18
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+18
-18
lines changed

‎google/cloud/spanner_v1/pool.py

Copy file name to clipboardExpand all lines: google/cloud/spanner_v1/pool.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def put(self, session):
503503
raise queue.Full
504504

505505
txn = session._transaction
506-
if txn is None or txn.committed or txn._rolled_back:
506+
if txn is None or txn.committed or txn.rolled_back:
507507
session.transaction()
508508
self._pending_sessions.put(session)
509509
else:

‎google/cloud/spanner_v1/session.py

Copy file name to clipboardExpand all lines: google/cloud/spanner_v1/session.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def transaction(self):
255255
raise ValueError("Session has not been created.")
256256

257257
if self._transaction is not None:
258-
self._transaction._rolled_back = True
258+
self._transaction.rolled_back = True
259259
del self._transaction
260260

261261
txn = self._transaction = Transaction(self)

‎google/cloud/spanner_v1/transaction.py

Copy file name to clipboardExpand all lines: google/cloud/spanner_v1/transaction.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Transaction(_SnapshotBase, _BatchBase):
3636

3737
committed = None
3838
"""Timestamp at which the transaction was successfully committed."""
39-
_rolled_back = False
39+
rolled_back = False
4040
_multi_use = True
4141
_execute_sql_count = 0
4242

@@ -58,7 +58,7 @@ def _check_state(self):
5858
if self.committed is not None:
5959
raise ValueError("Transaction is already committed")
6060

61-
if self._rolled_back:
61+
if self.rolled_back:
6262
raise ValueError("Transaction is already rolled back")
6363

6464
def _make_txn_selector(self):
@@ -85,7 +85,7 @@ def begin(self):
8585
if self.committed is not None:
8686
raise ValueError("Transaction already committed")
8787

88-
if self._rolled_back:
88+
if self.rolled_back:
8989
raise ValueError("Transaction is already rolled back")
9090

9191
database = self._session._database
@@ -105,7 +105,7 @@ def rollback(self):
105105
api = database.spanner_api
106106
metadata = _metadata_with_prefix(database.name)
107107
api.rollback(self._session.name, self._transaction_id, metadata=metadata)
108-
self._rolled_back = True
108+
self.rolled_back = True
109109
del self._session._transaction
110110

111111
def commit(self):

‎tests/unit/test_pool.py

Copy file name to clipboardExpand all lines: tests/unit/test_pool.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def _make_transaction(*args, **kw):
837837

838838
txn = mock.create_autospec(Transaction)(*args, **kw)
839839
txn.committed = None
840-
txn._rolled_back = False
840+
txn.rolled_back = False
841841
return txn
842842

843843

‎tests/unit/test_session.py

Copy file name to clipboardExpand all lines: tests/unit/test_session.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_transaction_w_existing_txn(self):
463463
another = session.transaction() # invalidates existing txn
464464

465465
self.assertIs(session._transaction, another)
466-
self.assertTrue(existing._rolled_back)
466+
self.assertTrue(existing.rolled_back)
467467

468468
def test_run_in_transaction_callback_raises_non_gax_error(self):
469469
from google.cloud.spanner_v1.proto.transaction_pb2 import (
@@ -506,7 +506,7 @@ def unit_of_work(txn, *args, **kw):
506506
txn, args, kw = called_with[0]
507507
self.assertIsInstance(txn, Transaction)
508508
self.assertIsNone(txn.committed)
509-
self.assertTrue(txn._rolled_back)
509+
self.assertTrue(txn.rolled_back)
510510
self.assertEqual(args, ())
511511
self.assertEqual(kw, {})
512512

@@ -561,7 +561,7 @@ def unit_of_work(txn, *args, **kw):
561561
txn, args, kw = called_with[0]
562562
self.assertIsInstance(txn, Transaction)
563563
self.assertIsNone(txn.committed)
564-
self.assertFalse(txn._rolled_back)
564+
self.assertFalse(txn.rolled_back)
565565
self.assertEqual(args, ())
566566
self.assertEqual(kw, {})
567567

‎tests/unit/test_transaction.py

Copy file name to clipboardExpand all lines: tests/unit/test_transaction.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_ctor_defaults(self):
7676
self.assertIs(transaction._session, session)
7777
self.assertIsNone(transaction._transaction_id)
7878
self.assertIsNone(transaction.committed)
79-
self.assertFalse(transaction._rolled_back)
79+
self.assertFalse(transaction.rolled_back)
8080
self.assertTrue(transaction._multi_use)
8181
self.assertEqual(transaction._execute_sql_count, 0)
8282

@@ -98,7 +98,7 @@ def test__check_state_already_rolled_back(self):
9898
session = _Session()
9999
transaction = self._make_one(session)
100100
transaction._transaction_id = self.TRANSACTION_ID
101-
transaction._rolled_back = True
101+
transaction.rolled_back = True
102102
with self.assertRaises(ValueError):
103103
transaction._check_state()
104104

@@ -125,7 +125,7 @@ def test_begin_already_begun(self):
125125
def test_begin_already_rolled_back(self):
126126
session = _Session()
127127
transaction = self._make_one(session)
128-
transaction._rolled_back = True
128+
transaction.rolled_back = True
129129
with self.assertRaises(ValueError):
130130
transaction.begin()
131131

@@ -187,7 +187,7 @@ def test_rollback_already_rolled_back(self):
187187
session = _Session()
188188
transaction = self._make_one(session)
189189
transaction._transaction_id = self.TRANSACTION_ID
190-
transaction._rolled_back = True
190+
transaction.rolled_back = True
191191
with self.assertRaises(ValueError):
192192
transaction.rollback()
193193

@@ -203,7 +203,7 @@ def test_rollback_w_other_error(self):
203203
with self.assertRaises(RuntimeError):
204204
transaction.rollback()
205205

206-
self.assertFalse(transaction._rolled_back)
206+
self.assertFalse(transaction.rolled_back)
207207

208208
def test_rollback_ok(self):
209209
from google.protobuf.empty_pb2 import Empty
@@ -218,7 +218,7 @@ def test_rollback_ok(self):
218218

219219
transaction.rollback()
220220

221-
self.assertTrue(transaction._rolled_back)
221+
self.assertTrue(transaction.rolled_back)
222222
self.assertIsNone(session._transaction)
223223

224224
session_id, txn_id, metadata = api._rolled_back
@@ -244,7 +244,7 @@ def test_commit_already_rolled_back(self):
244244
session = _Session()
245245
transaction = self._make_one(session)
246246
transaction._transaction_id = self.TRANSACTION_ID
247-
transaction._rolled_back = True
247+
transaction.rolled_back = True
248248
with self.assertRaises(ValueError):
249249
transaction.commit()
250250

@@ -546,7 +546,7 @@ def test_context_mgr_failure(self):
546546
raise Exception("bail out")
547547

548548
self.assertEqual(transaction.committed, None)
549-
self.assertTrue(transaction._rolled_back)
549+
self.assertTrue(transaction.rolled_back)
550550
self.assertEqual(len(transaction._mutations), 1)
551551

552552
self.assertEqual(api._committed, None)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.