-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: 4.18.2
-
Component/s: None
-
None
-
None
-
Python Drivers
-
None
-
None
-
None
-
None
-
None
-
None
The maxPoolSize docs say: "Can be either 0 or None, in which case there is no limit on the number of concurrent connections", and the pool treats both as unlimited (if not self.max_pool_size: self.max_pool_size = float("inf")).
However, _parse_pool_options in pymongo/client_options.py only exempts None from the minPoolSize check:
if max_pool_size is not None and min_pool_size > max_pool_size: raise ValueError("minPoolSize must be smaller or equal to maxPoolSize")
so 0 is treated as a real limit.
Reproduction
from pymongo import MongoClient MongoClient("mongodb://localhost", connect=False, maxPoolSize=None, minPoolSize=5) # OK MongoClient("mongodb://localhost", connect=False, maxPoolSize=0, minPoolSize=5) # ValueError: minPoolSize must be smaller or equal to maxPoolSize
Expected
Both calls are accepted, since 0 and None both mean "no limit".
Proposed fix
Skip the check when maxPoolSize is 0 or None:
if max_pool_size and min_pool_size > max_pool_size:
Environment: PyMongo 4.18.2, Python 3.12, Linux.