Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
Changelog
=========

Changes in Version 4.21.0 (unreleased)
--------------------------------------

Bug fixes
.........

- Fixed a bug where a cancelled async command published a
``CommandStartedEvent`` (and its "Command started" log message) without a
correlating ``CommandFailedEvent``. A cancellation now publishes the failure
before the ``CancelledError`` propagates (`PYTHON-6187`_).

.. _PYTHON-6187: https://jira.mongodb.org/browse/PYTHON-6187

Changes in Version 4.20.1 (2026/XX/XX)
Changes in Version 4.20.1 (2026/11/19)
--------------------------------------

Version 4.20.1 is a bug fix release.
Expand All @@ -25,8 +12,17 @@ Bug fixes
- Fixed a bug where ``getMore`` commands in load-balanced mode were not
retried when the server returned a retryable overload error
(`PYTHON-6262`_).
- Fixed a bug where a cancelled async command published a
``CommandStartedEvent`` (and its "Command started" log message) without a
correlating ``CommandFailedEvent``. A cancellation now publishes the failure
before the ``CancelledError`` propagates (`PYTHON-6187`_).
- Sanitize parsing error messages. (`PYTHON-6058`_)
- Improved credential validation. (`PYTHON-6073`_)

.. _PYTHON-6262: https://jira.mongodb.org/browse/PYTHON-6262
.. _PYTHON-6187: https://jira.mongodb.org/browse/PYTHON-6187
.. _PYTHON-6058: https://jira.mongodb.org/browse/PYTHON-6058
.. _PYTHON-6073: https://jira.mongodb.org/browse/PYTHON-6073

Changes in Version 4.20.0 (2026/11/12)
--------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pymongo/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import re

__version__ = "4.21.0.dev0"
__version__ = "4.20.1"


def get_version_tuple(version: str) -> tuple[int | str, ...]:
Expand Down
22 changes: 8 additions & 14 deletions pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@
from difflib import get_close_matches
from importlib.metadata import requires, version
from inspect import signature
from typing import (
TYPE_CHECKING,
Any,
NoReturn,
Self,
overload,
)
from typing import TYPE_CHECKING, Any, NoReturn, Self, overload
from urllib.parse import unquote_plus

from bson import SON
Expand Down Expand Up @@ -173,7 +167,7 @@ def clean_node(node: str) -> tuple[str, int]:


def raise_config_error(
key: str, suggestions: Optional[list[str]] = None, from_uri: bool = False
key: str, suggestions: list[str] | None = None, from_uri: bool = False
) -> NoReturn:
"""Raise ConfigurationError with the given key name.
Expand Down Expand Up @@ -236,8 +230,8 @@ def validate_non_negative_integer(option: str, value: Any) -> int:
return val


def validate_readable(option: str, value: Any, from_uri: bool = False) -> Optional[str]:
"""Validates that 'value' is file-like and readable."""
def validate_readable(option: str, value: Any, from_uri: bool = False) -> str | None:
"""Validate that 'value' is file-like and readable."""
if value is None:
return value
# First make sure its a string py3.3 open(True, 'r') succeeds
Expand Down Expand Up @@ -643,7 +637,7 @@ def validate_server_api_or_none(option: Any, value: Any) -> ServerApi | None:
return value


def validate_is_callable_or_none(option: Any, value: Any) -> Callable[..., Any] | None:
def validate_is_callable_or_none(option: Any, value: Any) -> Callable[[Any, Any], Any] | None:
"""Validate that 'value' is a callable."""
if value is None:
return value
Expand Down Expand Up @@ -710,7 +704,7 @@ def validate_auto_encryption_opts_or_none(option: Any, value: Any) -> Any | None

def validate_datetime_conversion(
option: Any, value: Any, from_uri: bool = False
) -> Optional[DatetimeConversion]:
) -> DatetimeConversion | None:
"""Validate a DatetimeConversion string."""
if value is None:
return DatetimeConversion.DATETIME
Expand Down Expand Up @@ -883,7 +877,7 @@ def validate_server_monitoring_mode(option: str, value: str, from_uri: bool = Fa
def _get_validator(
key: str,
validators: dict[str, Callable[[Any, Any], Any]],
normed_key: Optional[str] = None,
normed_key: str | None = None,
from_uri: bool = False,
) -> Callable[[Any, Any], Any]:
normed_key = normed_key or key
Expand Down Expand Up @@ -939,7 +933,7 @@ def get_setter_key(x: str) -> str:
opt, URI_OPTIONS_VALIDATOR_MAP, normed_key=normed_key, from_uri=from_uri
)
if from_uri and "from_uri" in signature(validator).parameters:
validated = validator(opt, value, from_uri=True)
validated = validator(opt, value, from_uri=True) # type: ignore[call-arg]
else:
validated = validator(opt, value)
except (ValueError, TypeError, ConfigurationError) as exc:
Expand Down
2 changes: 1 addition & 1 deletion pymongo/compression_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _have_zstd() -> bool:


def validate_compressors(
dummy: Any, value: Union[str, Iterable[str]], from_uri: bool = False
dummy: Any, value: str | Iterable[str], from_uri: bool = False
) -> list[str]:
try:
# `value` is string.
Expand Down
4 changes: 2 additions & 2 deletions pymongo/uri_parser_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _normalize_options(options: _CaseInsensitiveDictionary) -> _CaseInsensitiveD
def validate_options(
opts: Mapping[str, Any], warn: bool = False, from_uri: bool = False
) -> MutableMapping[str, Any]:
"""Validates and normalizes options passed in a MongoDB URI.
"""Validate and normalizes options passed in a MongoDB URI.
Returns a new dictionary of validated and normalized options. If warn is
False then errors will be thrown for invalid options, otherwise they will
Expand Down Expand Up @@ -444,7 +444,7 @@ def split_options(

if validate:
options = cast(
_CaseInsensitiveDictionary, validate_options(options, warn, from_uri=from_uri)
"_CaseInsensitiveDictionary", validate_options(options, warn, from_uri=from_uri)
)
if options.get("authsource") == "":
raise InvalidURI("the authSource database cannot be an empty string")
Expand Down
10 changes: 8 additions & 2 deletions test/test_uri_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def test_split_options(self):
# Test suggestions given when invalid kwarg passed. The key itself is
# not named: it comes from a connection string.

expected = r"Unknown option. Did you mean one of \(authsource, authmechanism, timeoutms\) or maybe a camelCase version of one\? Refer to docstring."
expected = (
r"Unknown option. Did you mean one of \(authsource, authmechanism, timeoutms\) "
r"or maybe a camelCase version of one\? Refer to docstring."
)
with self.assertRaisesRegex(ConfigurationError, expected):
split_options("auth=GSSAPI")

Expand Down Expand Up @@ -727,7 +730,10 @@ def test_parse_error_does_not_echo_value(self):
self.assertNotIn(value, str(ctx.exception))

def test_read_preference_mode_error_message(self):
expected = r"Not a valid read preference\. Must be one of: primary, primaryPreferred, secondary, secondaryPreferred, nearest"
expected = (
r"Not a valid read preference\. Must be one of: primary, primaryPreferred, "
r"secondary, secondaryPreferred, nearest"
)
with self.assertRaisesRegex(ValueError, expected):
parse_uri("mongodb://localhost/?readPreference=bogus")

Expand Down
Loading