From af67b0dd769c046f10c99c1e9faabe186dd7c410 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 19 Nov 2026 08:48:04 -0800 Subject: [PATCH 1/5] prep for 4.20.1 release --- doc/changelog.rst | 20 ++++++-------------- pymongo/_version.py | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 47d5b82f87..cd125b48b5 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,13 @@ 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`_). .. _PYTHON-6262: https://jira.mongodb.org/browse/PYTHON-6262 +.. _PYTHON-6187: https://jira.mongodb.org/browse/PYTHON-6187 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, ...]: From 4a14232aa9aaffb53ff1019f69b7156e06633daa Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 19 Nov 2026 08:56:39 -0800 Subject: [PATCH 2/5] fix typing and linting --- doc/changelog.rst | 2 ++ pymongo/common.py | 18 ++++++------------ pymongo/compression_support.py | 2 +- pymongo/uri_parser_shared.py | 4 ++-- test/test_uri_parser.py | 10 ++++++++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index cd125b48b5..f9f27bb8d2 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -16,6 +16,8 @@ Bug fixes ``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. +- Improved credential validation. .. _PYTHON-6262: https://jira.mongodb.org/browse/PYTHON-6262 .. _PYTHON-6187: https://jira.mongodb.org/browse/PYTHON-6187 diff --git a/pymongo/common.py b/pymongo/common.py index e8b7b53f96..9d1be8a32b 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 @@ -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 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") From 76082b117317c3ae6d977bceb41c60607bbb9ce8 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 19 Nov 2026 09:03:01 -0800 Subject: [PATCH 3/5] ignore typing error since the line above does the checking --- pymongo/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/common.py b/pymongo/common.py index 9d1be8a32b..101bfd474c 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -879,7 +879,7 @@ def _get_validator( validators: dict[str, Callable[[Any, Any], Any]], normed_key: str | None = None, from_uri: bool = False, -) -> Callable[[Any, Any], Any]: +) -> Callable[..., Any]: normed_key = normed_key or key try: return validators[normed_key] @@ -933,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: From 8dd8187a387b4ce9b422397214260cea3fc7b998 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 19 Nov 2026 09:03:46 -0800 Subject: [PATCH 4/5] this was an accident --- pymongo/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymongo/common.py b/pymongo/common.py index 101bfd474c..a424aab674 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -637,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 From 8070389e172de19ed75ae77a001e5930ca763f26 Mon Sep 17 00:00:00 2001 From: Iris Date: Thu, 19 Nov 2026 09:05:26 -0800 Subject: [PATCH 5/5] add python ticket numbers --- doc/changelog.rst | 6 ++++-- pymongo/common.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index f9f27bb8d2..0ebcbe8912 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -16,11 +16,13 @@ Bug fixes ``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. -- Improved credential validation. +- 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/common.py b/pymongo/common.py index a424aab674..a155c97ef8 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -879,7 +879,7 @@ def _get_validator( validators: dict[str, Callable[[Any, Any], Any]], normed_key: str | None = None, from_uri: bool = False, -) -> Callable[..., Any]: +) -> Callable[[Any, Any], Any]: normed_key = normed_key or key try: return validators[normed_key]