Skip to content

Commit fc7996d

Browse files
authored
chore(DRIVERS-2134): clarify write concern options in txn (#1712)
1 parent 50059b2 commit fc7996d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

source/transactions/tests/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ driver, use command monitoring instead.
7676
3. Test that `PoolClearedError` has `TransientTransactionError` label. Since there is no simple way to trigger
7777
`PoolClearedError`, this test should be implemented in a way that suites each driver the best.
7878

79+
## Options Inside Transaction Prose Tests.
80+
81+
These prose tests ensure drivers handle options inside a transaction where the unified tests do not suffice. Ensure
82+
these tests do not run against a standalone server.
83+
84+
### 1.0 Write concern not inherited from collection object inside transaction.
85+
86+
- Create a MongoClient running against a configured sharded/replica set/load balanced cluster.
87+
- Start a new session on the client.
88+
- Start a transaction on the session.
89+
- Instantiate a collection object in the driver with a default write concern of `{ w: 0 }`.
90+
- Insert the document `{ n: 1 }` on the instantiated collection.
91+
- Commit the transaction.
92+
- End the session.
93+
- Ensure the document was inserted and no error was thrown from the transaction.
94+
7995
## Changelog
8096

8197
- 2024-10-31: Add test for PoolClearedError.

source/transactions/transactions.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ Drivers MUST raise an error if the user provides or if defaults would result in
203203
Driver Sessions spec disallows using unacknowledged writes in a session. The error message MUST contain "transactions do
204204
not support unacknowledged write concerns".
205205

206+
If a higher level object, such as a Collection, is created inside a transaction, their write concern option MUST be
207+
ignored if provided and the transaction level write concern used instead. An example of expected behaviour is:
208+
209+
```python
210+
client = MongoClient("mongodb://host/?readPreference=nearest")
211+
coll = client.db.test
212+
with client.start_session() as s:
213+
with s.start_transaction():
214+
w_0_coll = db.get_collection("w_0_coll", writeConcern=WriteConcern(w=0))
215+
# This is allowed, the write concern of the transaction is used instead of w=0 from the collection.
216+
w_0_coll.insert_one({}, session=s)
217+
```
218+
206219
#### readPreference
207220

208221
The read preference to use for all read operations in this transaction.
@@ -1074,6 +1087,8 @@ objective of avoiding duplicate commits.
10741087

10751088
## **Changelog**
10761089

1090+
- 2024-11-01: Clarify collection options inside txn.
1091+
10771092
- 2024-11-01: Specify that ClientSession must be unpinned when ended.
10781093

10791094
- 2024-10-31: Clarify when drivers must add TransientTransactionError label.

0 commit comments

Comments
 (0)