Skip to content

Commit 192976b

Browse files
DRIVERS-2782 Re-work phrasing and tests concerning variable snapshotTime access (#1873)
1 parent 0bc7fb6 commit 192976b

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

source/sessions/snapshot-sessions.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ class ClientSession {
137137
}
138138
```
139139

140-
The `snapshotTime` field MUST be read-only; in APIs that expose `snapshotTime` with a getter, attempting to read it on a
141-
non-snapshot session MUST raise an error.
140+
On a non-snapshot session, the value of `snapshotTime` is undefined. Drivers MUST either raise an error when the
141+
property is accessed or return an unset value.
142142

143143
Transactions are not allowed with snapshot sessions. Calling `session.startTransaction(options)` on a snapshot session
144144
MUST raise an error.
@@ -257,6 +257,12 @@ don't have to be changed. This goal is met by defining a `SessionOptions` field
257257
it aligns better with the existing API, and requires minimal API changes. Future extensibility for snapshot reads would
258258
be best served by a session-based approach, as no API changes will be required.
259259

260+
### `snapshotTimeout` must be read-only
261+
262+
Allowing callers to mutate `snapshotTime` enables misuse patterns where applications overwrite `snapshotTime` on an
263+
existing session and then use that session in transactions, combining an inconsistent timestamp with an existing server
264+
session and triggering hard-to-diagnose write conflicts.
265+
260266
## Backwards Compatibility
261267

262268
The API changes to support snapshot reads extend the existing API but do not introduce any backward breaking changes.
@@ -271,7 +277,7 @@ C# driver will provide the reference implementation. The corresponding ticket is
271277

272278
## Changelog
273279

274-
- 2025-12-17: Clarify snapshotTime semantics: the field is either read-only or validated.
280+
- 2025-12-18: Make snapshot getter optional.
275281
- 2025-09-23: Exposed snapshotTime to applications.
276282
- 2024-05-08: Migrated from reStructuredText to Markdown.
277283
- 2021-06-15: Initial version.

source/sessions/tests/README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,27 @@ Snapshot sessions tests require server of version 5.0 or higher and replica set
270270

271271
Snapshot sessions tests require server of version 5.0 or higher and replica set or a sharded cluster deployment.
272272

273-
- Start a session by calling `startSession` with `snapshot = false`.
274-
275-
Drivers SHOULD implement one of the following approaches:
276-
277-
**Approach 1: Validation (preferred if idiomatic)**
278-
273+
- Start a session by calling `startSession` on with `snapshot = false`.
279274
- Try to access the session's snapshot time.
280275
- Assert that a client side error was raised.
276+
- Assert that the session's `snapshotTime` is unset.
277+
278+
Drivers MAY skip this test if they choose not to implement a getter for `snapshotTime`.
281279

282-
**Approach 2: Ensure Read-Only (if error-returning getters are not idiomatic)**
280+
### 23. Ensure `snapshotTime` is Read-Only
283281

282+
Snapshot sessions tests require server of version 5.0 or higher and replica set or a sharded cluster deployment.
283+
284+
- Start a session by calling `startSession` on with `snapshot = false`.
285+
- Assert that the session's `snapshotTime` is unset.
284286
- Attempt to mutate the session's `snapshotTime` field through any publicly accessible API.
285287
- Assert that the original session's `snapshotTime` remains unchanged.
286288

289+
Drivers MAY skip this test if they choose to expose a read-only `snapshotTime` property using an accessor method only.
290+
287291
## Changelog
288292

293+
- 2025-12-18: Make snapshot getter prose test optional.
289294
- 2025-09-25: Added tests for snapshotTime.
290295
- 2025-02-24: Test drivers do not gossip $clusterTime on SDAM.
291296
- 2024-05-08: Migrated from reStructuredText to Markdown.

0 commit comments

Comments
 (0)