diff --git a/doc/changelog.rst b/doc/changelog.rst index 47d5b82f87..0ebcbe8912 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -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. @@ -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) -------------------------------------- diff --git a/pymongo/_version.py b/pymongo/_version.py index 8cca2a6eaa..01750ac15c 100644 --- a/pymongo/_version.py +++ b/pymongo/_version.py @@ -18,7 +18,7 @@ import re -__version__ = "4.21.0.dev0" +__version__ = "4.20.1" def get_version_tuple(version: str) -> tuple[int | str, ...]: diff --git a/pymongo/common.py b/pymongo/common.py index e8b7b53f96..a155c97ef8 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/pymongo/compression_support.py b/pymongo/compression_support.py index aa3f550543..fd74157bfa 100644 --- a/pymongo/compression_support.py +++ b/pymongo/compression_support.py @@ -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. diff --git a/pymongo/uri_parser_shared.py b/pymongo/uri_parser_shared.py index 2f1d58fc20..1e36b7c1b1 100644 --- a/pymongo/uri_parser_shared.py +++ b/pymongo/uri_parser_shared.py @@ -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 @@ -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") diff --git a/test/test_uri_parser.py b/test/test_uri_parser.py index e8834aaa6a..3f8dea65d0 100644 --- a/test/test_uri_parser.py +++ b/test/test_uri_parser.py @@ -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") @@ -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")