From 821f4beade42ef1cedc1b9f2f8ce106f84ac6591 Mon Sep 17 00:00:00 2001 From: Maddipatla Chatan Date: Tue, 6 Oct 2026 17:28:41 +0530 Subject: [PATCH 1/2] 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/2] 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])