PYTHON-6021 Move _write_concern_for_cmd into BaseObject - #3036
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The refactor is low-risk and maintains existing behavior, with only a minor documentation consistency nit to address.
Pull request overview
This PR refactors write concern selection by moving _write_concern_for_cmd from collection implementations into common.BaseObject, so both synchronous and asynchronous collections share the same logic through inheritance.
Changes:
- Added
BaseObject._write_concern_for_cmdinpymongo/common.py. - Removed per-collection
_write_concern_for_cmdimplementations from both async and sync collection modules. - Ensures collection call sites continue using
self._write_concern_for_cmd(...)with a single shared implementation.
File summaries
| File | Description |
|---|---|
| pymongo/common.py | Introduces the shared _write_concern_for_cmd helper on BaseObject. |
| pymongo/asynchronous/collection.py | Removes the duplicated _write_concern_for_cmd method so AsyncCollection relies on BaseObject. |
| pymongo/synchronous/collection.py | Removes the duplicated _write_concern_for_cmd method so Collection relies on BaseObject (generated file). |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+981
to
+984
| def _write_concern_for_cmd( | ||
| self, cmd: Mapping[str, Any], session: Optional[_AgnosticClientSession] | ||
| ) -> WriteConcern: | ||
| raw_wc = cmd.get("writeConcern") |
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-6021
Changes in this PR
Move _write_concern_for_cmd into BaseObject
Test Plan
existing tests should continue to pass :)
Checklist
Checklist for Author
Checklist for Reviewer