-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5169 - Deprecate Hedged Reads option #2213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5aa363
PYTHON-5169 - Deprecate Hedged Reads option
NoahStapp 396b076
Add test, address review
NoahStapp ce05c69
Address review
NoahStapp 5b87911
Stacklevel 4 for constructor
NoahStapp c492a8f
Merge branch 'master' into PYTHON-5169
ShaneHarvey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
from __future__ import annotations | ||
|
||
import warnings | ||
from collections import abc | ||
from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence | ||
|
||
|
@@ -103,6 +104,11 @@ def _validate_hedge(hedge: Optional[_Hedge]) -> Optional[_Hedge]: | |
if not isinstance(hedge, dict): | ||
raise TypeError(f"hedge must be a dictionary, not {hedge!r}") | ||
|
||
warnings.warn( | ||
"The read preference 'hedge' option is deprecated in PyMongo 4.12+ because hedged reads are deprecated in MongoDB version 8.0+. Support for 'hedge' will be removed in PyMongo 5.0.", | ||
DeprecationWarning, | ||
stacklevel=4, | ||
) | ||
return hedge | ||
|
||
|
||
|
@@ -183,7 +189,9 @@ def max_staleness(self) -> int: | |
|
||
@property | ||
def hedge(self) -> Optional[_Hedge]: | ||
"""The read preference ``hedge`` parameter. | ||
"""**DEPRECATED** - The read preference 'hedge' option is deprecated in PyMongo 4.12+ because hedged reads are deprecated in MongoDB version 8.0+. Support for 'hedge' will be removed in PyMongo 5.0. | ||
|
||
The read preference ``hedge`` parameter. | ||
|
||
A dictionary that configures how the server will perform hedged reads. | ||
It consists of the following keys: | ||
|
@@ -203,6 +211,12 @@ def hedge(self) -> Optional[_Hedge]: | |
|
||
.. versionadded:: 3.11 | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's update this docstring with |
||
if self.__hedge is not None: | ||
warnings.warn( | ||
"The read preference 'hedge' option is deprecated in PyMongo 4.12+ because hedged reads are deprecated in MongoDB version 8.0+. Support for 'hedge' will be removed in PyMongo 5.0.", | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return self.__hedge | ||
|
||
@property | ||
|
@@ -312,7 +326,7 @@ class PrimaryPreferred(_ServerMode): | |
replication before it will no longer be selected for operations. | ||
Default -1, meaning no maximum. If it is set, it must be at least | ||
90 seconds. | ||
:param hedge: The :attr:`~hedge` to use if the primary is not available. | ||
:param hedge: **DEPRECATED** - The :attr:`~hedge` for this read preference. | ||
|
||
.. versionchanged:: 3.11 | ||
Added ``hedge`` parameter. | ||
|
@@ -354,7 +368,7 @@ class Secondary(_ServerMode): | |
replication before it will no longer be selected for operations. | ||
Default -1, meaning no maximum. If it is set, it must be at least | ||
90 seconds. | ||
:param hedge: The :attr:`~hedge` for this read preference. | ||
:param hedge: **DEPRECATED** - The :attr:`~hedge` for this read preference. | ||
|
||
.. versionchanged:: 3.11 | ||
Added ``hedge`` parameter. | ||
|
@@ -397,7 +411,7 @@ class SecondaryPreferred(_ServerMode): | |
replication before it will no longer be selected for operations. | ||
Default -1, meaning no maximum. If it is set, it must be at least | ||
90 seconds. | ||
:param hedge: The :attr:`~hedge` for this read preference. | ||
:param hedge: **DEPRECATED** - The :attr:`~hedge` for this read preference. | ||
|
||
.. versionchanged:: 3.11 | ||
Added ``hedge`` parameter. | ||
|
@@ -441,7 +455,7 @@ class Nearest(_ServerMode): | |
replication before it will no longer be selected for operations. | ||
Default -1, meaning no maximum. If it is set, it must be at least | ||
90 seconds. | ||
:param hedge: The :attr:`~hedge` for this read preference. | ||
:param hedge: **DEPRECATED** - The :attr:`~hedge` for this read preference. | ||
|
||
.. versionchanged:: 3.11 | ||
Added ``hedge`` parameter. | ||
|
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can hedge also appear in the URI/MongoClient kwarg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not listed in our docs page, so I don't believe so. You can create a read preference instance and pass that as a kwarg, but that will still pass through the read preference constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking