From aae48290cdf36740fc42742e09a7ad8354e0f77d Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Thu, 11 Sep 2025 13:35:05 -0400 Subject: [PATCH 1/3] PYTHON-5543 Fix asyncio import - Import and use BaseProtocol instead of Protocal in PyMongoBaseProtocoal implementation. Resolves issue with instance type check in uvloop that prevents correct buffered config from being set. --- doc/changelog.rst | 8 ++++++++ pymongo/network_layer.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 64c61e5877..0857503cf3 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,14 @@ Changelog ========= +Changes in Version 4.15.1 (XXXX/XX/XX) +-------------------------------------- + +Version 4.15.1 is a bug fix release. + +- Fixed a bug in ``MongoClient.network_layer`` and ``AsyncMongoClient.network_layer`` + that could cause an ``TimeoutError`` when connecting to servers. + Changes in Version 4.15.0 (2025/09/10) -------------------------------------- diff --git a/pymongo/network_layer.py b/pymongo/network_layer.py index 028316de34..a3900e30c1 100644 --- a/pymongo/network_layer.py +++ b/pymongo/network_layer.py @@ -22,7 +22,7 @@ import struct import sys import time -from asyncio import BaseTransport, BufferedProtocol, Future, Protocol, Transport +from asyncio import BaseProtocol, BaseTransport, BufferedProtocol, Future, Transport from typing import ( TYPE_CHECKING, Any, @@ -250,7 +250,7 @@ def recv_into(self, buffer: bytes | memoryview) -> int: return self.conn.recv_into(buffer) -class PyMongoBaseProtocol(Protocol): +class PyMongoBaseProtocol(BaseProtocol): def __init__(self, timeout: Optional[float] = None): self.transport: Transport = None # type: ignore[assignment] self._timeout = timeout From 8a5bd2e2c11c9feb326d481f6f1f0a0073684264 Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Thu, 11 Sep 2025 16:00:38 -0400 Subject: [PATCH 2/3] Fix changelog entry --- doc/changelog.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 0857503cf3..ed65cf1197 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,8 +6,9 @@ Changes in Version 4.15.1 (XXXX/XX/XX) Version 4.15.1 is a bug fix release. -- Fixed a bug in ``MongoClient.network_layer`` and ``AsyncMongoClient.network_layer`` - that could cause an ``TimeoutError`` when connecting to servers. +- Fixed a bug in ``AsyncMongoClient`` that caused a + ``ServerSelectionTimeoutError`` when used with `` with ``uvicorn`` and + ``uvloop``. Changes in Version 4.15.0 (2025/09/10) -------------------------------------- From 7dedc8e250a11ac7058387556649416516415eaa Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Thu, 11 Sep 2025 16:14:51 -0400 Subject: [PATCH 3/3] Update doc/changelog.rst Co-authored-by: Noah Stapp --- doc/changelog.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index ed65cf1197..8fb2d12f96 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -7,8 +7,7 @@ Changes in Version 4.15.1 (XXXX/XX/XX) Version 4.15.1 is a bug fix release. - Fixed a bug in ``AsyncMongoClient`` that caused a - ``ServerSelectionTimeoutError`` when used with `` with ``uvicorn`` and - ``uvloop``. + ``ServerSelectionTimeoutError`` when used with ``uvicorn``, ``FastAPI``, or ``uvloop``. Changes in Version 4.15.0 (2025/09/10) --------------------------------------