| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7324c9e commit 4e864a5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -249,6 +249,7 @@ def transaction(self): | |||
| 249 | 249 | ||
| 250 | 250 | if self._transaction is not None: | |
| 251 | 251 | self._transaction._rolled_back = True | |
| 252 | + del self._transaction | ||
| 252 | 253 | ||
| 253 | 254 | txn = self._transaction = Transaction(self) | |
| 254 | 255 | return txn | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,12 +24,24 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | class Transaction(_SnapshotBase, _BatchBase): | |
| 27 | - """Implement read-write transaction semantics for a session.""" | ||
| 27 | + """Implement read-write transaction semantics for a session. | ||
| 28 | + | ||
| 29 | + :type session: :class:`~google.cloud.spanner.session.Session` | ||
| 30 | + :param session: the session used to perform the commit | ||
| 31 | + | ||
| 32 | + :raises ValueError: if session has an existing transaction | ||
| 33 | + """ | ||
| 28 | 34 | committed = None | |
| 29 | 35 | """Timestamp at which the transaction was successfully committed.""" | |
| 30 | 36 | _rolled_back = False | |
| 31 | 37 | _multi_use = True | |
| 32 | 38 | ||
| 39 | + def __init__(self, session): | ||
| 40 | + if session._transaction is not None: | ||
| 41 | + raise ValueError("Session has existing transaction.") | ||
| 42 | + | ||
| 43 | + super(Transaction, self).__init__(session) | ||
| 44 | + | ||
| 33 | 45 | def _check_state(self): | |
| 34 | 46 | """Helper for :meth:`commit` et al. | |
| 35 | 47 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,12 @@ def _make_one(self, session, *args, **kwargs): | |||
| 47 | 47 | session._transaction = transaction | |
| 48 | 48 | return transaction | |
| 49 | 49 | ||
| 50 | + def test_ctor_session_w_existing_txn(self): | ||
| 51 | + session = _Session() | ||
| 52 | + session._transaction = object() | ||
| 53 | + with self.assertRaises(ValueError): | ||
| 54 | + transaction = self._make_one(session) | ||
| 55 | + | ||
| 50 | 56 | def test_ctor_defaults(self): | |
| 51 | 57 | session = _Session() | |
| 52 | 58 | transaction = self._make_one(session) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments