Skip to content

Commit b18ce9e

Browse files
Ensure that max >= min when creating pools.
1 parent 94bef53 commit b18ce9e

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

doc/src/release_notes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ Common Changes
5050
(`PR 496 <https://github.com/oracle/python-oracledb/pull/496>`__).
5151
#) Fix bug with GitHub build action merge artifacts step
5252
(`issue 495 <https://github.com/oracle/python-oracledb/issues/495>`__).
53+
#) Error ``DPY-2064: parameter 'max' should be greater than or equal to
54+
parameter 'min'`` is now raised when a call to
55+
:meth:`oracledb.create_pool()`, :meth:`oracledb.create_pool_async()`
56+
or :meth:`oracledb.PoolParams()` is made with parameter "max" less than the
57+
parameter "min". Previously python-oracledb Thin mode did not raise an
58+
error and python-oracledb Thick mode raised the exception
59+
``ORA-24413: Invalid number of sessions specified``.
5360
#) Improved the test suite and documentation.
5461

5562

src/oracledb/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def _raise_not_supported(feature: str) -> None:
287287
ERR_PARAMS_HOOK_HANDLER_FAILED = 2061
288288
ERR_PAYLOAD_CANNOT_BE_ENQUEUED = 2062
289289
ERR_SCROLL_OUT_OF_RESULT_SET = 2063
290+
ERR_POOL_MAX_LESS_THAN_MIN = 2064
290291

291292
# error numbers that result in NotSupportedError
292293
ERR_TIME_NOT_SUPPORTED = 3000
@@ -781,6 +782,9 @@ def _raise_not_supported(feature: str) -> None:
781782
ERR_POOL_HAS_BUSY_CONNECTIONS: (
782783
"connection pool cannot be closed because connections are busy"
783784
),
785+
ERR_POOL_MAX_LESS_THAN_MIN: (
786+
"parameter 'max' should be greater than or equal to parameter 'min'"
787+
),
784788
ERR_POOL_NO_CONNECTION_AVAILABLE: (
785789
"timed out waiting for the connection pool to return a connection"
786790
),

src/oracledb/impl/base/pool_params.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ cdef class PoolParamsImpl(ConnectParamsImpl):
9494
_set_int_param(args, "ping_interval", &self.ping_interval)
9595
_set_uint_param(args, "ping_timeout", &self.ping_timeout)
9696

97+
# verify that max >= min
98+
if self.max < self.min:
99+
errors._raise_err(errors.ERR_POOL_MAX_LESS_THAN_MIN)
100+
97101
# if the pool is dynamically sized (min != max) then ensure that the
98102
# increment value is non-zero (as otherwise the pool would never grow!)
99103
if self.max != self.min and self.increment == 0:

tests/test_2400_pool.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,11 @@ def hook(params):
10791079
self.assertEqual(conn.stmtcachesize, orig_stmtcachesize)
10801080
pool.close()
10811081

1082+
def test_2456(self):
1083+
"2456 - test creation of pool with min > max"
1084+
with self.assertRaisesFullCode("DPY-2064"):
1085+
test_env.get_pool(min=3, max=2)
1086+
10821087

10831088
if __name__ == "__main__":
10841089
test_env.run_test_cases()

tests/test_4700_pool_params.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
class TestCase(test_env.BaseTestCase):
3636
requires_connection = False
3737

38-
def __test_writable_parameter(self, name, value):
38+
def __test_writable_parameter(self, name, value, params=None):
3939
"""
4040
Tests that a writable parameter can be written to and the modified
4141
value read back successfully.
4242
"""
43-
params = oracledb.PoolParams()
43+
if params is None:
44+
params = oracledb.PoolParams()
4445
orig_value = getattr(params, name)
4546
copied_params = params.copy()
4647
args = {}
@@ -54,7 +55,7 @@ def __test_writable_parameter(self, name, value):
5455

5556
def test_4700(self):
5657
"4700 - test writable parameters"
57-
self.__test_writable_parameter("min", 8)
58+
self.__test_writable_parameter("min", 8, oracledb.PoolParams(max=10))
5859
self.__test_writable_parameter("max", 12)
5960
self.__test_writable_parameter("increment", 2)
6061
self.__test_writable_parameter("connectiontype", oracledb.Connection)
@@ -164,6 +165,8 @@ def test_4702(self):
164165
conn_string = f"{host}/{service_name}?pyo.{name}={str_value}"
165166
with self.subTest(name=name, value=str_value):
166167
params = oracledb.PoolParams()
168+
if name == "min" and actual_value > params.max:
169+
params.set(max=actual_value)
167170
params.parse_connect_string(conn_string)
168171
self.assertEqual(params.host, host)
169172
self.assertEqual(params.service_name, service_name)

tests/test_5500_pool_async.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ async def test_5541(self):
630630
with self.assertRaises(TypeError):
631631
test_env.get_pool_async(pool_alias=alias)
632632

633+
async def test_5542(self):
634+
"5542 - test creation of pool with min > max"
635+
with self.assertRaisesFullCode("DPY-2064"):
636+
test_env.get_pool_async(min=3, max=2)
637+
633638

634639
if __name__ == "__main__":
635640
test_env.run_test_cases()

0 commit comments

Comments
 (0)