Skip to content

PYTHON-6018 Consolidate backpressure helpers into helpers_shared.py - #3025

Open
NoahStapp wants to merge 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6018
Open

PYTHON-6018 Consolidate backpressure helpers into helpers_shared.py#3025
NoahStapp wants to merge 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6018

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

PYTHON-6018

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 August 31, 2026 21:13
@NoahStapp
NoahStapp requested review from blink1073 and a lite review from Copilot August 31, 2026 21:13

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

This PR consolidates the client backpressure retry/backoff helper (_RetryPolicy + exponential backoff) into pymongo/helpers_shared.py so both synchronous and asynchronous clients (and their tests) reference the same implementation.

Changes:

  • Moved _RetryPolicy and _backoff implementation from pymongo/{a,}synchronous/helpers.py into pymongo/helpers_shared.py.
  • Updated both sync/async MongoClient implementations to instantiate helpers_shared._RetryPolicy.
  • Simplified retryable read/write tests to patch pymongo.helpers_shared._RetryPolicy.backoff directly (removing _IS_SYNC branching).

Reviewed changes

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

Show a summary per file
File Description
test/test_retryable_writes.py Updates backoff mocking target to the shared helper module.
test/test_retryable_reads.py Updates backoff mocking target to the shared helper module.
test/asynchronous/test_retryable_writes.py Updates backoff mocking target to the shared helper module for async tests.
test/asynchronous/test_retryable_reads.py Updates backoff mocking target to the shared helper module for async tests.
pymongo/synchronous/mongo_client.py Switches sync client retry policy construction to helpers_shared._RetryPolicy.
pymongo/synchronous/helpers.py Removes local backpressure helper implementation now housed in helpers_shared.
pymongo/helpers_shared.py Adds shared backpressure helpers (_backoff, _RetryPolicy) and CSOT-aware should_retry.
pymongo/asynchronous/mongo_client.py Switches async client retry policy construction to helpers_shared._RetryPolicy and updates should_retry call to be non-awaited.
pymongo/asynchronous/helpers.py Removes local backpressure helper implementation now housed in helpers_shared.

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

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/helpers_shared.py 95.65% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@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

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