Skip to content

Commit cac0d55

Browse files
committed
PYTHON-1508 Remove autoStartTransaction and resync tests
Also use the test file's database name and collection name.
1 parent 335cb97 commit cac0d55

21 files changed

+83
-795
lines changed

pymongo/client_session.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,13 @@ class SessionOptions(object):
105105
:Parameters:
106106
- `causal_consistency` (optional): If True (the default), read
107107
operations are causally ordered within the session.
108-
- `auto_start_transaction` (optional): If True, any operation using
109-
the session automatically starts a transaction.
110108
- `default_transaction_options` (optional): The default
111109
TransactionOptions to use for transactions started on this session.
112110
"""
113111
def __init__(self,
114112
causal_consistency=True,
115-
auto_start_transaction=False,
116113
default_transaction_options=None):
117114
self._causal_consistency = causal_consistency
118-
self._auto_start_transaction = auto_start_transaction
119115
if default_transaction_options is not None:
120116
if not isinstance(default_transaction_options, TransactionOptions):
121117
raise TypeError(
@@ -129,15 +125,6 @@ def causal_consistency(self):
129125
"""Whether causal consistency is configured."""
130126
return self._causal_consistency
131127

132-
@property
133-
def auto_start_transaction(self):
134-
"""Whether any operation using the session automatically starts a
135-
transaction.
136-
137-
.. versionadded:: 3.7
138-
"""
139-
return self._auto_start_transaction
140-
141128
@property
142129
def default_transaction_options(self):
143130
"""The default TransactionOptions to use for transactions started on
@@ -349,7 +336,7 @@ def abort_transaction(self):
349336
def _finish_transaction(self, command_name):
350337
self._check_ended()
351338

352-
if not self._in_transaction_or_auto_start():
339+
if not self._in_transaction:
353340
raise InvalidOperation("No transaction started")
354341

355342
try:
@@ -424,24 +411,14 @@ def _in_transaction(self):
424411
"""True if this session has an active multi-statement transaction."""
425412
return self._transaction is not None
426413

427-
def _in_transaction_or_auto_start(self):
428-
"""True if this session has an active transaction or will have one."""
429-
if self._in_transaction:
430-
return True
431-
if self.options.auto_start_transaction:
432-
self.start_transaction()
433-
return True
434-
return False
435-
436414
def _txn_read_preference(self):
437415
"""Return read preference of this transaction or None."""
438-
if self._in_transaction_or_auto_start():
416+
if self._in_transaction:
439417
return self._transaction.opts.read_preference
440418
return None
441419

442420
def _apply_to(self, command, is_retryable, read_preference):
443421
self._check_ended()
444-
self._in_transaction_or_auto_start()
445422

446423
self._server_session.last_use = monotonic.time()
447424
command['lsid'] = self._server_session.session_id

pymongo/mongo_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,7 @@ def _retry_with_session(self, retryable, func, session, bulk):
10701070
Re-raises any exception thrown by func().
10711071
"""
10721072
retryable = (retryable and self.retry_writes
1073-
and session
1074-
and not session._in_transaction_or_auto_start())
1073+
and session and not session._in_transaction)
10751074
last_error = None
10761075
retrying = False
10771076

@@ -1361,7 +1360,6 @@ def _process_periodic_tasks(self):
13611360

13621361
def start_session(self,
13631362
causal_consistency=True,
1364-
auto_start_transaction=False,
13651363
default_transaction_options=None):
13661364
"""Start a logical session.
13671365
@@ -1393,7 +1391,6 @@ def start_session(self,
13931391
server_session = self._get_server_session()
13941392
opts = client_session.SessionOptions(
13951393
causal_consistency=causal_consistency,
1396-
auto_start_transaction=auto_start_transaction,
13971394
default_transaction_options=default_transaction_options)
13981395
return client_session.ClientSession(
13991396
self, server_session, opts, authset)

test/test_transactions.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,16 @@ def run_scenario(self):
299299
# "operation was interrupted" by killing the command's own session.
300300
pass
301301

302+
database_name = scenario_def['database_name']
303+
collection_name = scenario_def['collection_name']
302304
write_concern_db = client.get_database(
303-
'transaction-tests', write_concern=WriteConcern(w='majority'))
304-
305-
write_concern_db.test.drop()
306-
write_concern_db.create_collection('test')
305+
database_name, write_concern=WriteConcern(w='majority'))
306+
write_concern_coll = write_concern_db[collection_name]
307+
write_concern_coll.drop()
308+
write_concern_db.create_collection(collection_name)
307309
if scenario_def['data']:
308310
# Load data.
309-
write_concern_db.test.insert_many(scenario_def['data'])
311+
write_concern_coll.insert_many(scenario_def['data'])
310312

311313
# Create session0 and session1.
312314
sessions = {}
@@ -349,7 +351,7 @@ def run_scenario(self):
349351
self.addCleanup(end_sessions, sessions)
350352

351353
listener.results.clear()
352-
collection = client['transaction-tests'].test
354+
collection = client[database_name][collection_name]
353355

354356
for op in test['operations']:
355357
expected_result = op.get('result')

test/transactions/abort.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"database_name": "transaction-tests",
3+
"collection_name": "test",
24
"data": [],
35
"tests": [
46
{

0 commit comments

Comments
 (0)