(
self,
command: MutableMapping[str, Any],
is_retryable: bool,
read_preference: _ServerMode,
conn: Connection,
)
| 1091 | self._server_session.inc_transaction_id() |
| 1092 | |
| 1093 | def _apply_to( |
| 1094 | self, |
| 1095 | command: MutableMapping[str, Any], |
| 1096 | is_retryable: bool, |
| 1097 | read_preference: _ServerMode, |
| 1098 | conn: Connection, |
| 1099 | ) -> None: |
| 1100 | if not conn.supports_sessions: |
| 1101 | if not self._implicit: |
| 1102 | raise ConfigurationError("Sessions are not supported by this MongoDB deployment") |
| 1103 | return |
| 1104 | self._check_ended() |
| 1105 | self._materialize(conn.logical_session_timeout_minutes) |
| 1106 | if self.options.snapshot: |
| 1107 | self._update_read_concern(command, conn) |
| 1108 | |
| 1109 | self._server_session.last_use = time.monotonic() |
| 1110 | command["lsid"] = self._server_session.session_id |
| 1111 | |
| 1112 | if is_retryable: |
| 1113 | command["txnNumber"] = self._server_session.transaction_id |
| 1114 | return |
| 1115 | |
| 1116 | if self.in_transaction: |
| 1117 | if read_preference != ReadPreference.PRIMARY: |
| 1118 | raise InvalidOperation( |
| 1119 | f"read preference in a transaction must be primary, not: {read_preference!r}" |
| 1120 | ) |
| 1121 | |
| 1122 | if self._transaction.state == _TxnState.STARTING: |
| 1123 | # First command begins a new transaction. |
| 1124 | self._transaction.state = _TxnState.IN_PROGRESS |
| 1125 | command["startTransaction"] = True |
| 1126 | |
| 1127 | assert self._transaction.opts |
| 1128 | if self._transaction.opts.read_concern: |
| 1129 | rc = self._transaction.opts.read_concern.document |
| 1130 | if rc: |
| 1131 | command["readConcern"] = rc |
| 1132 | self._update_read_concern(command, conn) |
| 1133 | |
| 1134 | command["txnNumber"] = self._server_session.transaction_id |
| 1135 | command["autocommit"] = False |
| 1136 | |
| 1137 | def _start_retryable_write(self) -> None: |
| 1138 | self._check_ended() |
no test coverage detected