Skip to content

Commit c003b91

Browse files
Fixed bug in ConnectParams.set() that would clear the "ssl_context",
"appcontext", "shardingkey" and "supershardingkey" parameters if they were not included in the parameters. This also affected calls to oracledb.connect() and oracledb.create_pool() that made use of the DSN with credentials format.
1 parent bf8cd3e commit c003b91

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

doc/src/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ Common Changes
9191
``DPI-1040: LOB was already closed``.
9292
#) Fixed bug in :meth:`ConnectParams.get_connect_string()` when a value for
9393
the connection parameter ``purity`` has been specified.
94+
#) Fixed bug in :meth:`ConnectParams.set()` that would clear the
95+
``ssl_context``, ``appcontext``, ``shardingkey`` and ``supershardingkey``
96+
parameters if they were not included in the parameters. This also affected
97+
calls to :meth:`oracledb.connect()` and :meth:`oracledb.create_pool()` that
98+
made use of the DSN with credentials format.
9499
#) Fixed bug in the calculation of :data:`Cursor.rowcount` under some
95100
circumstances.
96101
#) Connection parameters that are strings now treat an empty string in the

src/oracledb/impl/base/connect_params.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ cdef class ConnectParamsImpl:
144144
Sets the property values based on the supplied arguments. All values
145145
not supplied will be left unchanged.
146146
"""
147-
self._external_handle = args.get("handle", 0)
147+
self._external_handle = args.get("handle", self._external_handle)
148148
_set_str_param(args, "user", self)
149149
_set_str_param(args, "proxy_user", self)
150150
if self.proxy_user is None and self.user is not None:
@@ -159,12 +159,12 @@ cdef class ConnectParamsImpl:
159159
_set_bool_param(args, "matchanytag", &self.matchanytag)
160160
_set_uint_param(args, "stmtcachesize", &self.stmtcachesize)
161161
_set_bool_param(args, "disable_oob", &self.disable_oob)
162-
self.ssl_context = args.get("ssl_context")
162+
_set_obj_param(args, "ssl_context", self)
163163
_set_str_param(args, "debug_jdwp", self)
164164
_set_str_param(args, "config_dir", self)
165-
self.appcontext = args.get("appcontext")
166-
self.shardingkey = args.get("shardingkey")
167-
self.supershardingkey = args.get("supershardingkey")
165+
_set_obj_param(args, "appcontext", self)
166+
_set_obj_param(args, "shardingkey", self)
167+
_set_obj_param(args, "supershardingkey", self)
168168
self._default_description.set_from_connect_data_args(args)
169169
self._default_description.set_from_description_args(args)
170170
self._default_description.set_from_security_args(args)

src/oracledb/impl/base/utils.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ cdef int _set_uint_param(dict args, str name, uint32_t* out_val) except -1:
9191
out_val[0] = int(in_val)
9292

9393

94+
cdef int _set_obj_param(dict args, str name, object target) except -1:
95+
"""
96+
Sets an object parameter to the value provided in the dictionary, if a
97+
value is provided. This value is then set directly on the target.
98+
"""
99+
in_val = args.get(name)
100+
if in_val is not None:
101+
setattr(target, name, in_val)
102+
103+
94104
cdef int _set_pool_boundary_param(dict args, str name,
95105
object target) except -1:
96106
"""

tests/test_4500_connect_params.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828

2929
import os
30+
import ssl
3031
import tempfile
3132
import random
3233

@@ -792,6 +793,30 @@ def test_4570(self):
792793
)
793794
params.parse_connect_string(connect_string)
794795

796+
def test_4571(self):
797+
"4571 - calling set() doesn't clear object parameters"
798+
sharding_key = [1, 2, 3]
799+
super_sharding_key = [4, 5, 6]
800+
app_context = [("NAMESPACE", "KEY", "VALUE")]
801+
ssl_context = ssl.create_default_context()
802+
params = oracledb.ConnectParams(
803+
shardingkey=sharding_key,
804+
supershardingkey=super_sharding_key,
805+
appcontext=app_context,
806+
ssl_context=ssl_context,
807+
)
808+
self.assertEqual(params.appcontext, app_context)
809+
self.assertEqual(params.shardingkey, sharding_key)
810+
self.assertEqual(params.supershardingkey, super_sharding_key)
811+
self.assertEqual(params.ssl_context, ssl_context)
812+
user = "user_4571"
813+
params.set(user=user)
814+
self.assertEqual(params.user, user)
815+
self.assertEqual(params.appcontext, app_context)
816+
self.assertEqual(params.shardingkey, sharding_key)
817+
self.assertEqual(params.supershardingkey, super_sharding_key)
818+
self.assertEqual(params.ssl_context, ssl_context)
819+
795820

796821
if __name__ == "__main__":
797822
test_env.run_test_cases()

0 commit comments

Comments
 (0)