From 821f4beade42ef1cedc1b9f2f8ce106f84ac6591 Mon Sep 17 00:00:00 2001 From: Maddipatla Chatan Date: Tue, 6 Oct 2026 17:28:41 +0530 Subject: [PATCH 1/4] Fix condition for minPoolSize validation --- pymongo/client_options.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymongo/client_options.py b/pymongo/client_options.py index 99a2bcb4e4..b42635ef2c 100644 --- a/pymongo/client_options.py +++ b/pymongo/client_options.py @@ -160,7 +160,8 @@ def _parse_pool_options( max_pool_size = options.get("maxpoolsize", common.MAX_POOL_SIZE) min_pool_size = options.get("minpoolsize", common.MIN_POOL_SIZE) max_idle_time_seconds = options.get("maxidletimems", common.MAX_IDLE_TIME_SEC) - if max_pool_size is not None and min_pool_size > max_pool_size: + # A maxPoolSize of 0 or None means no limit. + if max_pool_size and min_pool_size > max_pool_size: raise ValueError("minPoolSize must be smaller or equal to maxPoolSize") connect_timeout = options.get("connecttimeoutms", common.CONNECT_TIMEOUT) socket_timeout = options.get("sockettimeoutms") From f6e45588347977f8cb6c8b75c715ac739070ec26 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Fri, 16 Oct 2026 11:38:55 -0400 Subject: [PATCH 2/4] PYTHON-6149 Add regression test and fix max_pool_size docstring --- pymongo/pool_options.py | 2 +- test/test_pooling.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pymongo/pool_options.py b/pymongo/pool_options.py index 69f194206e..63279d7e27 100644 --- a/pymongo/pool_options.py +++ b/pymongo/pool_options.py @@ -498,7 +498,7 @@ def max_pool_size(self) -> float: """The maximum allowable number of concurrent connections to each connected server. Requests to a server will block if there are `maxPoolSize` outstanding connections to the requested server. - Defaults to 100. Cannot be 0. + Defaults to 100. A value of 0 or ``None`` means no limit. When a server's pool has reached `max_pool_size`, operations for that server block waiting for a socket to be returned to the pool. If diff --git a/test/test_pooling.py b/test/test_pooling.py index d690de0ffb..16fcccb377 100644 --- a/test/test_pooling.py +++ b/test/test_pooling.py @@ -200,9 +200,28 @@ def test_max_pool_size_validation(self): self.assertRaises(ValueError, MongoClient, host=host, port=port, maxPoolSize="foo") + self.assertRaises( + ValueError, MongoClient, host=host, port=port, maxPoolSize=10, minPoolSize=20 + ) + c = MongoClient(host=host, port=port, maxPoolSize=100, connect=False) self.assertEqual(c.options.pool_options.max_pool_size, 100) + def test_max_pool_size_no_limit_with_min_pool_size(self): + # A maxPoolSize of 0 or None means no limit, so minPoolSize must + # still be allowed (PYTHON-6149). + host, port = client_context.host, client_context.port + for max_pool_size in (0, None): + c = MongoClient( + host=host, + port=port, + maxPoolSize=max_pool_size, + minPoolSize=5, + connect=False, + ) + self.assertEqual(c.options.pool_options.max_pool_size, max_pool_size) + self.assertEqual(c.options.pool_options.min_pool_size, 5) + def test_no_disconnect(self): run_cases(self.c, [NonUnique, Unique, InsertOneAndFind]) From 82a3c1464350abca7e26a0a4547ec692978ccdf2 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Fri, 16 Oct 2026 11:48:46 -0400 Subject: [PATCH 3/4] PYTHON-6149 Add test to async source for synchro --- test/asynchronous/test_pooling.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/asynchronous/test_pooling.py b/test/asynchronous/test_pooling.py index 9bd221f6e7..30783a73f1 100644 --- a/test/asynchronous/test_pooling.py +++ b/test/asynchronous/test_pooling.py @@ -200,9 +200,28 @@ async def test_max_pool_size_validation(self): self.assertRaises(ValueError, AsyncMongoClient, host=host, port=port, maxPoolSize="foo") + self.assertRaises( + ValueError, AsyncMongoClient, host=host, port=port, maxPoolSize=10, minPoolSize=20 + ) + c = AsyncMongoClient(host=host, port=port, maxPoolSize=100, connect=False) self.assertEqual(c.options.pool_options.max_pool_size, 100) + async def test_max_pool_size_no_limit_with_min_pool_size(self): + # A maxPoolSize of 0 or None means no limit, so minPoolSize must + # still be allowed (PYTHON-6149). + host, port = await async_client_context.host, await async_client_context.port + for max_pool_size in (0, None): + c = AsyncMongoClient( + host=host, + port=port, + maxPoolSize=max_pool_size, + minPoolSize=5, + connect=False, + ) + self.assertEqual(c.options.pool_options.max_pool_size, max_pool_size) + self.assertEqual(c.options.pool_options.min_pool_size, 5) + async def test_no_disconnect(self): await run_cases(self.c, [NonUnique, Unique, InsertOneAndFind]) From 869b9ce30fa6dbbe0219434ab12c4943622b127a Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Fri, 16 Oct 2026 16:08:28 -0400 Subject: [PATCH 4/4] PYTHON-6149 Add changelog entry for minPoolSize validation fix --- doc/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/changelog.rst b/doc/changelog.rst index c2b9fe2485..02bfd1e46e 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -13,8 +13,13 @@ Bug fixes default ``UNSPECIFIED`` UUID representation, and raise :class:`~bson.errors.InvalidBSON` when UUID conversion is requested (`PYTHON-6172`_). +- Fixed a bug where ``MongoClient(maxPoolSize=0, minPoolSize>0)`` raised + ``ValueError``, even though ``maxPoolSize=0`` means "no limit". The + ``minPoolSize <= maxPoolSize`` validation now treats both ``0`` and ``None`` + as unlimited (`PYTHON-6149`_). .. _PYTHON-6172: https://jira.mongodb.org/browse/PYTHON-6172 +.. _PYTHON-6149: https://jira.mongodb.org/browse/PYTHON-6149 Changes in Version 4.19.0 (2026/10/14) --------------------------------------