Skip to content

PYTHON-6019 Consolidate mongo_client module-level helpers into shared… - #3031

Merged
NoahStapp merged 2 commits into
mongodb:mainfrom
NoahStapp:PYTHON-6019
Sep 1, 2026
Merged

PYTHON-6019 Consolidate mongo_client module-level helpers into shared…#3031
NoahStapp merged 2 commits into
mongodb:mainfrom
NoahStapp:PYTHON-6019

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

… file

PYTHON-6019

Changes in this PR

See ticket.

Test Plan

Existing test suite.

Checklist

Checklist for Author

  • [ ] Did you update the changelog (if necessary)?
  • Is there test coverage?
  • [ ] 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?

@NoahStapp
NoahStapp requested a review from a team as a code owner September 1, 2026 15:48
@NoahStapp
NoahStapp requested review from sleepyStick and a lite review from Copilot September 1, 2026 15:48

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.

Pull request overview

Refactors MongoClient module-level helper logic by extracting common internals into a new shared module so the synchronous and asynchronous clients can reuse identical implementations.

Changes:

  • Introduces pymongo/mongo_client_shared.py to host shared internal helpers (_add_retryable_write_error, _after_fork_child, _detect_external_db).
  • Updates both pymongo/asynchronous/mongo_client.py and pymongo/synchronous/mongo_client.py to import and use the shared helpers instead of local duplicates.
  • Adjusts register_at_fork wiring to call the shared _after_fork_child with the appropriate client registry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pymongo/synchronous/mongo_client.py Removes duplicated helper implementations and uses shared helpers; updates register_at_fork callback wiring.
pymongo/asynchronous/mongo_client.py Removes duplicated helper implementations and uses shared helpers; updates register_at_fork callback wiring.
pymongo/mongo_client_shared.py New internal module containing shared MongoClient helpers used by both sync/async implementations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pymongo/asynchronous/mongo_client.py
Comment thread pymongo/mongo_client_shared.py
Comment thread pymongo/synchronous/mongo_client.py
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/mongo_client_shared.py 86.36% 5 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@NoahStapp
NoahStapp merged commit f9f9b03 into mongodb:main Sep 1, 2026
84 of 86 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