Skip to content

Commit 61b7d0f

Browse files
committed
Configurable read concern with start_transaction
1 parent 09891a4 commit 61b7d0f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pymongo/client_session.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ def __init__(self, read_concern=None, write_concern=None):
130130
raise ConfigurationError(
131131
"transactions must use an acknowledged write concern, "
132132
"not: %r" % (write_concern,))
133-
133+
134134
@property
135135
def read_concern(self):
136136
"""This transaction's :class:`~read_concern.ReadConcern`."""
137137
return self._read_concern
138-
138+
139139
@property
140140
def write_concern(self):
141141
"""This transaction's :class:`~write_concern.WriteConcern`."""
@@ -387,11 +387,18 @@ def _apply_to(self, command, is_retryable, read_preference):
387387
# First statement begins a new transaction.
388388
self._server_session._transaction_id += 1
389389
command['startTransaction'] = True
390-
read_concern = command.setdefault('readConcern', {})
391-
read_concern['level'] = 'snapshot'
390+
391+
if self._transaction.opts.read_concern:
392+
rc = self._transaction.opts.read_concern.document
393+
else:
394+
rc = {}
395+
392396
if (self.options.causal_consistency
393397
and self.operation_time is not None):
394-
read_concern['afterClusterTime'] = self.operation_time
398+
rc['afterClusterTime'] = self.operation_time
399+
400+
if rc:
401+
command['readConcern'] = rc
395402

396403
command['txnNumber'] = self._server_session.transaction_id
397404
command['stmtId'] = self._server_session.statement_id

0 commit comments

Comments
 (0)