PYTHON-5676 Consolidate Command Execution Logic#2789
Draft
aclark4life wants to merge 3 commits intomongodb:masterfrom
Draft
PYTHON-5676 Consolidate Command Execution Logic#2789aclark4life wants to merge 3 commits intomongodb:masterfrom
aclark4life wants to merge 3 commits intomongodb:masterfrom
Conversation
…ion() Since MIN_SUPPORTED_WIRE_VERSION=8 (MongoDB 4.2+), use_command() always returns True and OP_MSG is always used. Remove the unreachable OP_QUERY branches from Server.run_operation(), along with the dead else-branches in Cursor and CommandCursor that referenced _OpReply. - Hard-code use_cmd=True / apply_timeout=True in run_operation() - Always use user_fields=_CURSOR_DOC_FIELDS and legacy_response=False - Remove isinstance(reply, _OpMsg) exhaust check (reply is always _OpMsg) - Hard-code from_command=True in Response/PinnedResponse construction - Remove dead else-branches with assert isinstance(response.data, _OpReply) in Cursor._send_message and CommandCursor._send_message - Add scope document PYTHON-5676-scope.md outlining all four phases
Eliminate the ~13-line _COMMAND_LOGGER/_debug_log boilerplate that was copy-pasted identically across five command execution paths. Add three helpers to pymongo/command_helpers.py and call them from all five sites. - New pymongo/command_helpers.py: _log_command_started, _log_command_succeeded, _log_command_failed — pure functions, no I/O, no async/sync split needed - network.py, server.py, bulk.py, client_bulk.py: replace inline _debug_log blocks with helper calls; remove _COMMAND_LOGGER/_CommandStatusMessage imports where no longer needed
Extract _network_command_core() from network.command() to handle the common send/receive/APM/decrypt pipeline. Both the standard command path and the cursor (find/getMore) path now use the same core function. - New _network_command_core() in network.py: takes a pre-built message and handles APM, send_message, receive_message, unpack, process, check, decrypt — returns (docs, reply, duration) - command() is now a thin wrapper: encode → _network_command_core → return docs[0] - run_operation() is now a thin wrapper: build message → _network_command_core → wrap in Response/PinnedResponse - _CURSOR_DOC_FIELDS moved from server.py to network.py (only used in core) - server.py drops _decode_all_selective, _check_command_response, _convert_exception, NotPrimaryError, OperationFailure imports
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.
PYTHON-5676
Changes in this PR
Test Plan
Checklist
Checklist for Author
Checklist for Reviewer