Skip to content

PYTHON-6021 Move _write_concern_for_cmd into BaseObject - #3036

Merged
sleepyStick merged 2 commits into
mongodb:mainfrom
sleepyStick:PYTHON-6021
Sep 4, 2026
Merged

PYTHON-6021 Move _write_concern_for_cmd into BaseObject#3036
sleepyStick merged 2 commits into
mongodb:mainfrom
sleepyStick:PYTHON-6021

Conversation

@sleepyStick

@sleepyStick sleepyStick commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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

  • [NA] Did you update the changelog (if necessary)?
  • Is there test coverage?
  • [NA] Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/common.py 60.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@sleepyStick
sleepyStick marked this pull request as ready for review September 4, 2026 17:47
Copilot AI lite review requested due to automatic review settings September 4, 2026 17:47
@sleepyStick
sleepyStick requested a review from a team as a code owner September 4, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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_cmd in pymongo/common.py.
  • Removed per-collection _write_concern_for_cmd implementations 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 thread pymongo/common.py
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")

@blink1073 blink1073 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sleepyStick
sleepyStick merged commit 22a2ec8 into mongodb:main Sep 4, 2026
90 of 91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants