PYTHON-5436 - Always include session on getMores if the initial curso…#2794
Open
NoahStapp wants to merge 2 commits intomongodb:masterfrom
Open
PYTHON-5436 - Always include session on getMores if the initial curso…#2794NoahStapp wants to merge 2 commits intomongodb:masterfrom
NoahStapp wants to merge 2 commits intomongodb:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a session-handling edge case in PyMongo’s cursor getMore path so that a cursor opened with a session keeps sending that session’s lsid even if the checked-out connection later reports supports_sessions=False (for example after a stepdown/pool state change).
Changes:
- Adjusted client-session command application logic to preserve
lsidongetMoreonce a session has already been materialized. - Added synchronous and asynchronous regression tests that simulate session support being lost on pooled connections after the initial
find. - Removed a few now-unused imports from the touched test modules.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
test/test_session.py |
Adds a sync regression test for preserving lsid on getMore after simulated session-support loss. |
test/asynchronous/test_session.py |
Adds the async counterpart to the new regression test. |
pymongo/synchronous/client_session.py |
Updates sync session command application logic for getMore with an already-materialized session. |
pymongo/asynchronous/client_session.py |
Updates async session command application logic with the same getMore behavior change. |
aclark4life
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…r used a session
PYTHON-5436
Changes in this PR
Fix a bug where a server stepdown could cause cursors opened with sessions to return server errors on getMores due to lost session support.
Test Plan
Added a new integration test.
Checklist
Checklist for Author
[ ] Did you update the changelog (if necessary)?[ ] Is any followup work tracked in a JIRA ticket? If so, add link(s).Checklist for Reviewer