From 2703e74142645591430f6b1d162b6a5dc9ccf3f4 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:30:42 -0700 Subject: [PATCH 01/32] Bump version in preparation for new changes. --- doc/src/release_notes.rst | 13 +++++++++++++ src/oracledb/version.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 86646806..93237767 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -13,6 +13,19 @@ Release changes are listed as affecting Thin Mode (the default runtime behavior of python-oracledb), as affecting the optional :ref:`Thick Mode `, or as being 'Common' for changes that impact both modes. +oracledb `3.4.1 `__ (TBD) +-------------------------------------------------------------------------------------------- + +Thin Mode Changes ++++++++++++++++++ + +Thick Mode Changes +++++++++++++++++++ + +Common Changes +++++++++++++++ + + oracledb `3.4.0 `__ (October 2025) ----------------------------------------------------------------------------------------------------- diff --git a/src/oracledb/version.py b/src/oracledb/version.py index 44b21913..56f8d3e7 100644 --- a/src/oracledb/version.py +++ b/src/oracledb/version.py @@ -30,4 +30,4 @@ # file doc/src/conf.py both reference this file directly. # ----------------------------------------------------------------------------- -__version__ = "3.4.0" +__version__ = "3.4.1" From 8c0581ca12b6ed80f241bb3e2139e6165dbc6404 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:31:19 -0700 Subject: [PATCH 02/32] Update ODPI-C. --- src/oracledb/impl/thick/odpi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oracledb/impl/thick/odpi b/src/oracledb/impl/thick/odpi index a6ac6133..a98ef338 160000 --- a/src/oracledb/impl/thick/odpi +++ b/src/oracledb/impl/thick/odpi @@ -1 +1 @@ -Subproject commit a6ac6133646856ea1563bd09aa57a0aeac9b40c8 +Subproject commit a98ef3384310081155e753063ef19c3e9abd9c23 From 5cd753ee3afd14a505d0385ef75dd7cadafaff18 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:31:31 -0700 Subject: [PATCH 03/32] Test suite updates. --- tests/conftest.py | 3 ++- tests/test_2400_pool.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 40014370..f12fe856 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -385,9 +385,10 @@ def get_admin_connection(self, use_async=False): """ Returns an administrative connection to the database. """ - self._initialize() if not self.admin_user or not self.admin_password: pytest.skip("missing administrative credentials") + if self.use_thick_mode and oracledb.is_thin_mode(): + oracledb.init_oracle_client(lib_dir=self.oracle_client_path) params = self.get_connect_params() if self.admin_user.upper() == "SYS": params = params.copy() diff --git a/tests/test_2400_pool.py b/tests/test_2400_pool.py index 4c930d9e..f81adfee 100644 --- a/tests/test_2400_pool.py +++ b/tests/test_2400_pool.py @@ -434,7 +434,6 @@ def test_2411(skip_unless_thick_mode, test_env): min=2, max=8, increment=3, - getmode=oracledb.POOL_GETMODE_NOWAIT, session_callback=callback, ) tags = [ @@ -1066,6 +1065,6 @@ def test_2457(skip_if_drcp, test_env): def test_2458(test_env): "2458 - connection to database with bad password" - pool = test_env.get_pool(password=test_env.main_password + "X") with test_env.assert_raises_full_code("ORA-01017"): + pool = test_env.get_pool(password=test_env.main_password + "X") pool.acquire() From 2f90c3f53683fb6cd7d805d851761a34d674824b Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:31:46 -0700 Subject: [PATCH 04/32] Fixed bug that caused "ORA-03137: malformed TTC packet from client rejected" exception to be raised when attempting to call parse() on a scrollable cursor. --- doc/src/release_notes.rst | 4 ++++ src/oracledb/impl/thin/messages/execute.pyx | 2 +- tests/test_4200_cursor_scrollable.py | 23 +++++++++++++++++++++ tests/test_8600_cursor_scrollable_async.py | 23 +++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 93237767..b5808be2 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -25,6 +25,10 @@ Thick Mode Changes Common Changes ++++++++++++++ +#) Fixed bug that caused ``ORA-03137: malformed TTC packet from client + rejected`` exception to be raised when attempting to call + :meth:`Cursor.parse()` on a scrollable cursor. + oracledb `3.4.0 `__ (October 2025) ----------------------------------------------------------------------------------------------------- diff --git a/src/oracledb/impl/thin/messages/execute.pyx b/src/oracledb/impl/thin/messages/execute.pyx index cda1183a..9f8468ed 100644 --- a/src/oracledb/impl/thin/messages/execute.pyx +++ b/src/oracledb/impl/thin/messages/execute.pyx @@ -81,7 +81,7 @@ cdef class ExecuteMessage(MessageWithData): exec_flags |= TNS_EXEC_FLAGS_IMPLICIT_RESULTSET if not self.scroll_operation: options |= TNS_EXEC_OPTION_EXECUTE - if cursor_impl.scrollable: + if cursor_impl.scrollable and not self.parse_only: exec_flags |= TNS_EXEC_FLAGS_SCROLLABLE if stmt._cursor_id == 0 or stmt._is_ddl: options |= TNS_EXEC_OPTION_PARSE diff --git a/tests/test_4200_cursor_scrollable.py b/tests/test_4200_cursor_scrollable.py index 7a341731..2f39d87a 100644 --- a/tests/test_4200_cursor_scrollable.py +++ b/tests/test_4200_cursor_scrollable.py @@ -223,3 +223,26 @@ def test_4214(conn): (value,) = cursor.fetchone() assert value == 6.25 assert cursor.rowcount == 5 + + +def test_4215(conn): + "4215 - test parse() on a scrollable cursor" + cursor = conn.cursor(scrollable=True) + statement = """ + select 1 from dual + union all + select 2 from dual + union all + select 3 from dual + union all + select 4 from dual + union all + select 5 from dual + """ + cursor.parse(statement) + cursor.execute(statement) + (fetched_value,) = cursor.fetchone() + assert fetched_value == 1 + cursor.scroll(mode="last") + (fetched_value,) = cursor.fetchone() + assert fetched_value == 5 diff --git a/tests/test_8600_cursor_scrollable_async.py b/tests/test_8600_cursor_scrollable_async.py index 636d72c9..46a1c4e2 100644 --- a/tests/test_8600_cursor_scrollable_async.py +++ b/tests/test_8600_cursor_scrollable_async.py @@ -226,3 +226,26 @@ async def test_8614(async_conn): (value,) = await cursor.fetchone() assert value == 6.25 assert cursor.rowcount == 5 + + +async def test_8615(async_conn): + "8615 - test parse() on a scrollable cursor" + cursor = async_conn.cursor(scrollable=True) + statement = """ + select 1 from dual + union all + select 2 from dual + union all + select 3 from dual + union all + select 4 from dual + union all + select 5 from dual + """ + await cursor.parse(statement) + await cursor.execute(statement) + (fetched_value,) = await cursor.fetchone() + assert fetched_value == 1 + await cursor.scroll(mode="last") + (fetched_value,) = await cursor.fetchone() + assert fetched_value == 5 From 05b15612bfe17409653a2c96f1cae620909ba1ce Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:32:15 -0700 Subject: [PATCH 05/32] Fixed segfault on some platforms when trying to execute queries returning vector columns. --- doc/src/release_notes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index b5808be2..242e4600 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -22,6 +22,10 @@ Thin Mode Changes Thick Mode Changes ++++++++++++++++++ +#) Fixed segfault on some platforms when trying to execute queries returning + vector columns + (`ODPI-C `__ dependency update). + Common Changes ++++++++++++++ From fd3ca3305997d4f97c34b6e91dac99562a20cbf6 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:32:39 -0700 Subject: [PATCH 06/32] Fixed bug when using bind variables with scrollable cursors. --- doc/src/release_notes.rst | 2 ++ src/oracledb/impl/thin/constants.pxi | 1 + src/oracledb/impl/thin/cursor.pyx | 12 ++++++------ src/oracledb/impl/thin/messages/execute.pyx | 3 ++- tests/test_4200_cursor_scrollable.py | 19 +++++++++++++++++++ tests/test_8600_cursor_scrollable_async.py | 19 +++++++++++++++++++ 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 242e4600..f5b9feac 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -19,6 +19,8 @@ oracledb `3.4.1 desired_row return message @@ -259,8 +259,8 @@ cdef class ThinCursorImpl(BaseThinCursorImpl): cdef: Protocol protocol = self._conn_impl._protocol MessageWithData message - if self._statement._sql is None: - message = self._create_message(ExecuteMessage, cursor) + if self._statement._sql is None or self.scrollable: + message = self._create_execute_message(cursor) else: message = self._create_message(FetchMessage, cursor) protocol._process_single_message(message) @@ -357,8 +357,8 @@ cdef class AsyncThinCursorImpl(BaseThinCursorImpl): Internal method used for fetching rows from the database. """ cdef MessageWithData message - if self._statement._sql is None: - message = self._create_message(ExecuteMessage, cursor) + if self._statement._sql is None or self.scrollable: + message = self._create_execute_message(cursor) else: message = self._create_message(FetchMessage, cursor) await self._conn_impl._protocol._process_single_message(message) diff --git a/src/oracledb/impl/thin/messages/execute.pyx b/src/oracledb/impl/thin/messages/execute.pyx index 9f8468ed..c5381c21 100644 --- a/src/oracledb/impl/thin/messages/execute.pyx +++ b/src/oracledb/impl/thin/messages/execute.pyx @@ -83,6 +83,7 @@ cdef class ExecuteMessage(MessageWithData): options |= TNS_EXEC_OPTION_EXECUTE if cursor_impl.scrollable and not self.parse_only: exec_flags |= TNS_EXEC_FLAGS_SCROLLABLE + exec_flags |= TNS_EXEC_FLAGS_NO_CANCEL_ON_EOF if stmt._cursor_id == 0 or stmt._is_ddl: options |= TNS_EXEC_OPTION_PARSE if stmt._is_query: @@ -100,7 +101,7 @@ cdef class ExecuteMessage(MessageWithData): options |= TNS_EXEC_OPTION_NOT_PLSQL elif stmt._is_plsql and num_params > 0: options |= TNS_EXEC_OPTION_PLSQL_BIND - if num_params > 0: + if num_params > 0 and not self.scroll_operation: options |= TNS_EXEC_OPTION_BIND if self.batcherrors: options |= TNS_EXEC_OPTION_BATCH_ERRORS diff --git a/tests/test_4200_cursor_scrollable.py b/tests/test_4200_cursor_scrollable.py index 2f39d87a..7f9a1e21 100644 --- a/tests/test_4200_cursor_scrollable.py +++ b/tests/test_4200_cursor_scrollable.py @@ -246,3 +246,22 @@ def test_4215(conn): cursor.scroll(mode="last") (fetched_value,) = cursor.fetchone() assert fetched_value == 5 + + +def test_4216(conn): + "4216 - test scroll operation with bind values" + cursor = conn.cursor(scrollable=True) + base_value = 4215 + cursor.execute( + """ + select :base_value + 1 from dual + union all + select :base_value + 2 from dual + union all + select :base_value + 3 from dual + """, + dict(base_value=base_value), + ) + cursor.scroll(mode="last") + (fetched_value,) = cursor.fetchone() + assert fetched_value == base_value + 3 diff --git a/tests/test_8600_cursor_scrollable_async.py b/tests/test_8600_cursor_scrollable_async.py index 46a1c4e2..de3dc219 100644 --- a/tests/test_8600_cursor_scrollable_async.py +++ b/tests/test_8600_cursor_scrollable_async.py @@ -249,3 +249,22 @@ async def test_8615(async_conn): await cursor.scroll(mode="last") (fetched_value,) = await cursor.fetchone() assert fetched_value == 5 + + +async def test_8616(async_conn): + "8616 - test scroll operation with bind values" + cursor = async_conn.cursor(scrollable=True) + base_value = 4215 + await cursor.execute( + """ + select :base_value + 1 from dual + union all + select :base_value + 2 from dual + union all + select :base_value + 3 from dual + """, + dict(base_value=base_value), + ) + await cursor.scroll(mode="last") + (fetched_value,) = await cursor.fetchone() + assert fetched_value == base_value + 3 From 8af6668990c914bbe5585e40db1a9173faaa3147 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:34:52 -0700 Subject: [PATCH 07/32] Doc updates. --- doc/src/user_guide/aq.rst | 4 ++++ src/oracledb/__init__.py | 2 +- src/oracledb/aq.py | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/src/user_guide/aq.rst b/doc/src/user_guide/aq.rst index 6db66b5a..1bd838e6 100644 --- a/doc/src/user_guide/aq.rst +++ b/doc/src/user_guide/aq.rst @@ -43,9 +43,13 @@ types which are detailed below. - Supported for single and array message enqueuing and dequeuing when using Oracle Client 19c (or later) and connected to Oracle Database 19c (or later). * - JSON - Supported when using Oracle Database 21c (or later). In python-oracle Thick mode, Oracle Client libraries 21c (or later) are also needed. + + Buffered messaging using the :data:`~oracledb.MSG_BUFFERED` delivery mode is not supported for JSON payloads. - Supported for single message enqueuing and dequeuing when using Oracle Client libraries 21c (or later) and Oracle Database 21c (or later). Array enqueuing and dequeuing is not supported for JSON payloads. + + Buffered messaging using the :data:`~oracledb.MSG_BUFFERED` delivery mode is not supported for JSON payloads. * - JMS - Supported - Supported for single and array message enqueuing and dequeuing when using Oracle Client 19 (or later) and Oracle Database version 23 (or later). diff --git a/src/oracledb/__init__.py b/src/oracledb/__init__.py index a05263f8..7e11e7f0 100644 --- a/src/oracledb/__init__.py +++ b/src/oracledb/__init__.py @@ -734,7 +734,7 @@ needs to be created prior to enqueuing buffered messages. This mode is not supported for bulk array operations in python-oracledb Thick -mode. +mode, and for JSON payloads. """ MSG_PERSISTENT: int = constants.MSG_PERSISTENT diff --git a/src/oracledb/aq.py b/src/oracledb/aq.py index cbd62be4..ebca3ec8 100644 --- a/src/oracledb/aq.py +++ b/src/oracledb/aq.py @@ -326,6 +326,9 @@ def deliverymode(self) -> int: :data:`~oracledb.MSG_PERSISTENT` (default), :data:`~oracledb.MSG_BUFFERED`, or :data:`~oracledb.MSG_PERSISTENT_OR_BUFFERED`. + + Note that :data:`~oracledb.MSG_BUFFERED` is not supported for JSON + payloads. """ raise AttributeError("deliverymode can only be written") @@ -435,6 +438,9 @@ def deliverymode(self) -> int: enqueued. It should be one of the values :data:`~oracledb.MSG_PERSISTENT` (default) or :data:`~oracledb.MSG_BUFFERED`. + + Note that :data:`~oracledb.MSG_BUFFERED` is not supported for JSON + payloads. """ raise AttributeError("deliverymode can only be written") From 3df1328a2a9553752408f8f7b079704b0d47c6b2 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:37:07 -0700 Subject: [PATCH 08/32] Error "DPY-2068: scroll operation is not supported on a non-scrollable cursor" is now raised when using the Cursor.scroll() method on a non-scrollable cursor. --- doc/src/release_notes.rst | 3 +++ src/oracledb/cursor.py | 4 ++++ src/oracledb/errors.py | 4 ++++ tests/test_4200_cursor_scrollable.py | 8 ++++++++ tests/test_8600_cursor_scrollable_async.py | 8 ++++++++ 5 files changed, 27 insertions(+) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index f5b9feac..76c81928 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -34,6 +34,9 @@ Common Changes #) Fixed bug that caused ``ORA-03137: malformed TTC packet from client rejected`` exception to be raised when attempting to call :meth:`Cursor.parse()` on a scrollable cursor. +#) Error ``DPY-2068: scroll operation is not supported on a non-scrollable + cursor`` is now raised when using :meth:`Cursor.scroll()` method on a + non-scrollable cursor. oracledb `3.4.0 `__ (October 2025) diff --git a/src/oracledb/cursor.py b/src/oracledb/cursor.py index 42c7ae8c..7d1a2ed3 100644 --- a/src/oracledb/cursor.py +++ b/src/oracledb/cursor.py @@ -1034,6 +1034,8 @@ def scroll(self, value: int = 0, mode: str = "relative") -> None: scroll operation would position the cursor outside of the result set. """ self._verify_open() + if not self._impl.scrollable: + errors._raise_err(errors.ERR_SCROLL_NOT_SUPPORTED) self._impl.scroll(self, value, mode) @@ -1366,4 +1368,6 @@ async def scroll(self, value: int = 0, mode: str = "relative") -> None: scroll operation would position the cursor outside of the result set. """ self._verify_open() + if not self._impl.scrollable: + errors._raise_err(errors.ERR_SCROLL_NOT_SUPPORTED) await self._impl.scroll(self, value, mode) diff --git a/src/oracledb/errors.py b/src/oracledb/errors.py index a0ac34f9..7b32ed43 100644 --- a/src/oracledb/errors.py +++ b/src/oracledb/errors.py @@ -291,6 +291,7 @@ def _raise_not_supported(feature: str) -> None: ERR_ARROW_SPARSE_VECTOR_NOT_ALLOWED = 2065 ERR_EMPTY_STATEMENT = 2066 ERR_WRONG_DIRECT_PATH_DATA_TYPE = 2067 +ERR_SCROLL_NOT_SUPPORTED = 2068 # error numbers that result in NotSupportedError ERR_TIME_NOT_SUPPORTED = 3000 @@ -894,6 +895,9 @@ def _raise_not_supported(feature: str) -> None: ERR_PYTHON_VALUE_NOT_SUPPORTED: ( 'Python value of type "{type_name}" is not supported' ), + ERR_SCROLL_NOT_SUPPORTED: ( + "scroll operation is not supported on a non-scrollable cursor" + ), ERR_SCROLL_OUT_OF_RESULT_SET: ( "scroll operation would go out of the result set" ), diff --git a/tests/test_4200_cursor_scrollable.py b/tests/test_4200_cursor_scrollable.py index 7f9a1e21..dc34c50c 100644 --- a/tests/test_4200_cursor_scrollable.py +++ b/tests/test_4200_cursor_scrollable.py @@ -265,3 +265,11 @@ def test_4216(conn): cursor.scroll(mode="last") (fetched_value,) = cursor.fetchone() assert fetched_value == base_value + 3 + + +def test_4217(conn, test_env): + "4217 - test calling scroll() on a non-scrollable cursor" + cursor = conn.cursor() + cursor.execute("select NumberCol from TestNumbers order by IntCol") + with test_env.assert_raises_full_code("DPY-2068"): + cursor.scroll(mode="first") diff --git a/tests/test_8600_cursor_scrollable_async.py b/tests/test_8600_cursor_scrollable_async.py index de3dc219..5bd47140 100644 --- a/tests/test_8600_cursor_scrollable_async.py +++ b/tests/test_8600_cursor_scrollable_async.py @@ -268,3 +268,11 @@ async def test_8616(async_conn): await cursor.scroll(mode="last") (fetched_value,) = await cursor.fetchone() assert fetched_value == base_value + 3 + + +async def test_8617(async_conn, test_env): + "8717 - test calling scroll() on a non-scrollable cursor" + cursor = async_conn.cursor() + await cursor.execute("select NumberCol from TestNumbers order by IntCol") + with test_env.assert_raises_full_code("DPY-2068"): + await cursor.scroll(mode="first") From c3c25730709a51bf264b819d310f2c025d602af5 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:42:33 -0700 Subject: [PATCH 09/32] Fixed bug when setting "SOURCE_ROUTE" on the "DESCRIPTION" section of a full connect descriptor instead of the "ADDRESS_LIST" section. --- doc/src/release_notes.rst | 2 ++ src/oracledb/impl/base/parsers.pyx | 1 + tests/test_4500_connect_params.py | 3 +-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 76c81928..5db2207e 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -20,6 +20,8 @@ Thin Mode Changes +++++++++++++++++ #) Fixed bug when using bind variables with scrollable cursors. +#) Fixed bug when setting ``SOURCE_ROUTE`` on the ``DESCRIPTION`` section of a + full connect descriptor instead of the ``ADDRESS_LIST`` section. Thick Mode Changes ++++++++++++++++++ diff --git a/src/oracledb/impl/base/parsers.pyx b/src/oracledb/impl/base/parsers.pyx index 19fa04eb..a894595e 100644 --- a/src/oracledb/impl/base/parsers.pyx +++ b/src/oracledb/impl/base/parsers.pyx @@ -362,6 +362,7 @@ cdef class ConnectStringParser(BaseParser): description.set_from_security_args(sub_args) address_lists = desc_args.get("address_list", desc_args) if not isinstance(address_lists, list): + description.source_route = False address_lists = [address_lists] for list_args in address_lists: address_list = AddressList() diff --git a/tests/test_4500_connect_params.py b/tests/test_4500_connect_params.py index bc745135..69b85ff7 100644 --- a/tests/test_4500_connect_params.py +++ b/tests/test_4500_connect_params.py @@ -588,8 +588,7 @@ def test_4531(): params.parse_connect_string(connect_string) source_route_clause = "(SOURCE_ROUTE=ON)" if has_section else "" connect_string = ( - f"(DESCRIPTION={source_route_clause}" - f"(ADDRESS_LIST={source_route_clause}" + f"(DESCRIPTION=(ADDRESS_LIST={source_route_clause}" "(ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=1521))" "(ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=1522)))" "(CONNECT_DATA=(SERVICE_NAME=my_service_35)))" From 55e94919a70b598240badffb54ed4cc67fe46df1 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:44:28 -0700 Subject: [PATCH 10/32] Raise helpful exception for requested_schema programming errors. --- doc/src/release_notes.rst | 7 ++++++ src/oracledb/errors.py | 5 ++++ src/oracledb/impl/base/cursor.pyx | 7 ++++++ tests/test_9300_dataframe_requested_schema.py | 25 +++++++++++++++++++ ...t_9400_dataframe_requested_schema_async.py | 23 +++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 5db2207e..cd3216f6 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -36,6 +36,13 @@ Common Changes #) Fixed bug that caused ``ORA-03137: malformed TTC packet from client rejected`` exception to be raised when attempting to call :meth:`Cursor.parse()` on a scrollable cursor. +#) Error ``DPY-2069: requested schema has {num_schema_columns} columns defined + but {num_fetched_columns} columns are being fetched`` is now raised when + the number of elements in the ``requested_schema`` parameter to + :meth:`Connection.fetch_df_all()` and :meth:`Connection.fetch_df_batches()` + doesn't match the number of columns being fetched. Previously this scenario + would throw unhelpful execptions or cause a segfault under certain + circumstances. #) Error ``DPY-2068: scroll operation is not supported on a non-scrollable cursor`` is now raised when using :meth:`Cursor.scroll()` method on a non-scrollable cursor. diff --git a/src/oracledb/errors.py b/src/oracledb/errors.py index 7b32ed43..44d406f7 100644 --- a/src/oracledb/errors.py +++ b/src/oracledb/errors.py @@ -292,6 +292,7 @@ def _raise_not_supported(feature: str) -> None: ERR_EMPTY_STATEMENT = 2066 ERR_WRONG_DIRECT_PATH_DATA_TYPE = 2067 ERR_SCROLL_NOT_SUPPORTED = 2068 +ERR_WRONG_REQUESTED_SCHEMA_LENGTH = 2069 # error numbers that result in NotSupportedError ERR_TIME_NOT_SUPPORTED = 3000 @@ -1007,6 +1008,10 @@ def _raise_not_supported(feature: str) -> None: 'found object of type "{actual_schema}.{actual_name}" when ' 'expecting object of type "{expected_schema}.{expected_name}"' ), + ERR_WRONG_REQUESTED_SCHEMA_LENGTH: ( + "requested schema has {num_schema_columns} columns defined but " + "{num_fetched_columns} are being fetched" + ), ERR_WRONG_SCROLL_MODE: ( "scroll mode must be relative, absolute, first or last" ), diff --git a/src/oracledb/impl/base/cursor.pyx b/src/oracledb/impl/base/cursor.pyx index b78e7d74..54978d2b 100644 --- a/src/oracledb/impl/base/cursor.pyx +++ b/src/oracledb/impl/base/cursor.pyx @@ -326,6 +326,13 @@ cdef class BaseCursorImpl: Initializes the fetch variable lists in preparation for creating the fetch variables used in fetching rows from the database. """ + cdef ssize_t num_schema_columns + if self.schema_impl is not None: + num_schema_columns = len(self.schema_impl.child_schemas) + if num_schema_columns != num_columns: + errors._raise_err(errors.ERR_WRONG_REQUESTED_SCHEMA_LENGTH, + num_schema_columns=num_schema_columns, + num_fetched_columns=num_columns) self.fetch_metadata = [None] * num_columns self.fetch_vars = [None] * num_columns self.fetch_var_impls = [None] * num_columns diff --git a/tests/test_9300_dataframe_requested_schema.py b/tests/test_9300_dataframe_requested_schema.py index c851ea11..d457ded3 100644 --- a/tests/test_9300_dataframe_requested_schema.py +++ b/tests/test_9300_dataframe_requested_schema.py @@ -755,3 +755,28 @@ def test_9327(value, conn, test_env): conn.fetch_df_all( "select :1 from dual", [value], requested_schema=requested_schema ) + + +@pytest.mark.parametrize("num_elements", [1, 3]) +def test_9328(num_elements, conn, test_env): + "9328 - fetch_df_all() with wrong requested_schema size" + elements = [(f"COL_{i}", pyarrow.string()) for i in range(num_elements)] + requested_schema = pyarrow.schema(elements) + with test_env.assert_raises_full_code("DPY-2069"): + conn.fetch_df_all( + "select user, user from dual", requested_schema=requested_schema + ) + + +@pytest.mark.parametrize("num_elements", [1, 3]) +def test_9329(num_elements, conn, test_env): + "9329 - fetch_df_batches() with wrong requested_schema size" + elements = [(f"COL_{i}", pyarrow.string()) for i in range(num_elements)] + requested_schema = pyarrow.schema(elements) + with test_env.assert_raises_full_code("DPY-2069"): + list( + conn.fetch_df_batches( + "select user, user from dual", + requested_schema=requested_schema, + ) + ) diff --git a/tests/test_9400_dataframe_requested_schema_async.py b/tests/test_9400_dataframe_requested_schema_async.py index ea52254c..1308b15d 100644 --- a/tests/test_9400_dataframe_requested_schema_async.py +++ b/tests/test_9400_dataframe_requested_schema_async.py @@ -778,3 +778,26 @@ async def test_9427(value, async_conn, test_env): await async_conn.fetch_df_all( "select :1 from dual", [value], requested_schema=requested_schema ) + + +@pytest.mark.parametrize("num_elements", [1, 3]) +async def test_9428(num_elements, async_conn, test_env): + "9428 - fetch_df_all() with wrong requested_schema size" + elements = [(f"COL_{i}", pyarrow.string()) for i in range(num_elements)] + requested_schema = pyarrow.schema(elements) + with test_env.assert_raises_full_code("DPY-2069"): + await async_conn.fetch_df_all( + "select user, user from dual", requested_schema=requested_schema + ) + + +@pytest.mark.parametrize("num_elements", [1, 3]) +async def test_9429(num_elements, async_conn, test_env): + "9429 - fetch_df_batches() with wrong requested_schema size" + elements = [(f"COL_{i}", pyarrow.string()) for i in range(num_elements)] + requested_schema = pyarrow.schema(elements) + with test_env.assert_raises_full_code("DPY-2069"): + async for df in async_conn.fetch_df_batches( + "select user, user from dual", requested_schema=requested_schema + ): + pass From 75417f1628cd09a46d20446401b61425c66d82e1 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:45:05 -0700 Subject: [PATCH 11/32] Ensure that PL/SQL errors found while building the schema are reported. --- tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/conftest.py b/tests/conftest.py index f12fe856..b5e784ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -665,6 +665,7 @@ def run_sql_script(self, conn, script_name, **kwargs): prev_name = name prev_obj_type = obj_type print(" %s/%s %s" % (line_num, position, text)) + assert prev_name is None def skip_unless_client_version(self, major_version, minor_version=0): """ From 20e37fe66b66c93edc2bcdd9befc3b1f02a46643 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:45:27 -0700 Subject: [PATCH 12/32] Fixed bug when adding a call to a PL/SQL function which returns LOBs to a pipeline. --- doc/src/release_notes.rst | 2 + src/oracledb/impl/thin/connection.pyx | 77 ++++++--------------------- tests/sql/create_schema.sql | 13 +++++ tests/test_7600_pipelining_async.py | 17 ++++++ 4 files changed, 48 insertions(+), 61 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index cd3216f6..1eef507f 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -19,6 +19,8 @@ oracledb `3.4.1 `. #) Fixed bug when using bind variables with scrollable cursors. #) Fixed bug when setting ``SOURCE_ROUTE`` on the ``DESCRIPTION`` section of a full connect descriptor instead of the ``ADDRESS_LIST`` section. diff --git a/src/oracledb/impl/thin/connection.pyx b/src/oracledb/impl/thin/connection.pyx index 6a820a52..c83bd620 100644 --- a/src/oracledb/impl/thin/connection.pyx +++ b/src/oracledb/impl/thin/connection.pyx @@ -721,6 +721,7 @@ cdef class AsyncThinConnImpl(BaseThinConnImpl): PipelineOpImpl op_impl = result_impl.operation uint8_t op_type = op_impl.op_type AsyncThinCursorImpl cursor_impl + BindVar bind_var # all operations other than commit make use of a cursor if op_type == PIPELINE_OP_TYPE_COMMIT: @@ -732,23 +733,27 @@ cdef class AsyncThinConnImpl(BaseThinConnImpl): # resend the message if that is required (for operations that fetch # LOBS, for example) - cursor_impl = message_with_data.cursor_impl + cursor_impl = message_with_data.cursor_impl if message.resend: await protocol._process_message(message) - await message.postprocess_async() - if op_type in ( - PIPELINE_OP_TYPE_FETCH_ONE, - PIPELINE_OP_TYPE_FETCH_MANY, - PIPELINE_OP_TYPE_FETCH_ALL, - ): - result_impl.rows = [] - while cursor_impl._buffer_rowcount > 0: - result_impl.rows.append(cursor_impl._create_row()) + await message.postprocess_async() + if op_impl.op_type == PIPELINE_OP_TYPE_CALL_FUNC: + bind_var = cursor_impl.bind_vars[0] + result_impl.return_value = bind_var.var_impl.get_value(0) + elif op_type in ( + PIPELINE_OP_TYPE_FETCH_ONE, + PIPELINE_OP_TYPE_FETCH_MANY, + PIPELINE_OP_TYPE_FETCH_ALL, + ): + result_impl.rows = [] + while cursor_impl._buffer_rowcount > 0: + result_impl.rows.append(cursor_impl._create_row()) result_impl.fetch_metadata = cursor_impl.fetch_metadata # for fetchall(), perform as many round trips as are required to # complete the fetch - if op_type == PIPELINE_OP_TYPE_FETCH_ALL: + if op_type == PIPELINE_OP_TYPE_FETCH_ALL \ + and cursor_impl._more_rows_to_fetch: fetch_message = cursor_impl._create_message( FetchMessage, message_with_data.cursor ) @@ -980,55 +985,6 @@ cdef class AsyncThinConnImpl(BaseThinConnImpl): messages.append(message) return messages - cdef int _populate_pipeline_op_result(self, Message message) except -1: - """ - Populates the pipeline operation result object. - """ - cdef: - MessageWithData message_with_data - AsyncThinCursorImpl cursor_impl - PipelineOpResultImpl result_impl - PipelineOpImpl op_impl - BindVar bind_var - result_impl = message.pipeline_result_impl - op_impl = result_impl.operation - if op_impl.op_type == PIPELINE_OP_TYPE_COMMIT: - return 0 - message_with_data = message - cursor_impl = message_with_data.cursor_impl - if op_impl.op_type == PIPELINE_OP_TYPE_CALL_FUNC: - bind_var = cursor_impl.bind_vars[0] - result_impl.return_value = bind_var.var_impl.get_value(0) - elif op_impl.op_type in ( - PIPELINE_OP_TYPE_FETCH_ONE, - PIPELINE_OP_TYPE_FETCH_MANY, - PIPELINE_OP_TYPE_FETCH_ALL, - ): - result_impl.rows = [] - while cursor_impl._buffer_rowcount > 0: - result_impl.rows.append(cursor_impl._create_row()) - - cdef int _populate_pipeline_op_results( - self, list messages, bint continue_on_error - ) except -1: - """ - Populates the pipeline operation result objects associated with the - messages that were processed on the database. - """ - cdef: - PipelineOpResultImpl result_impl - Message message - for message in messages: - result_impl = message.pipeline_result_impl - if result_impl.error is not None or message.resend: - continue - try: - self._populate_pipeline_op_result(message) - except Exception as e: - if not continue_on_error: - raise - result_impl._capture_err(e) - async def _run_pipeline_op_without_pipelining( self, object conn, PipelineOpResultImpl result_impl ): @@ -1262,7 +1218,6 @@ cdef class AsyncThinConnImpl(BaseThinConnImpl): self.pipeline_mode = TNS_PIPELINE_MODE_ABORT_ON_ERROR self._send_messages_for_pipeline(messages, continue_on_error) await protocol.end_pipeline(self, messages, continue_on_error) - self._populate_pipeline_op_results(messages, continue_on_error) await self._complete_pipeline_ops(messages, continue_on_error) async def run_pipeline_without_pipelining( diff --git a/tests/sql/create_schema.sql b/tests/sql/create_schema.sql index d7d5d5c3..9f35eb5b 100644 --- a/tests/sql/create_schema.sql +++ b/tests/sql/create_schema.sql @@ -1559,6 +1559,11 @@ create or replace package &main_user..pkg_TestLOBs as a_ReplaceValue varchar2 ); + function GetLOB ( + a_Num number, + a_Format varchar2 + ) return clob; + end; / @@ -1591,5 +1596,13 @@ create or replace package body &main_user..pkg_TestLOBs as end if; end; + function GetLOB ( + a_Num number, + a_Format varchar2 + ) return clob is + begin + return to_clob(replace(a_Format, '{}', to_char(a_Num))); + end; + end; / diff --git a/tests/test_7600_pipelining_async.py b/tests/test_7600_pipelining_async.py index ad84328c..d00489be 100644 --- a/tests/test_7600_pipelining_async.py +++ b/tests/test_7600_pipelining_async.py @@ -1009,3 +1009,20 @@ async def test_7648(async_conn, test_env): res = await async_conn.run_pipeline(pipeline) assert [res[-1].rows] == [[(clob_1_value,), (clob_2_value,)]] assert [res[-2].rows] == [[(clob_1_value,), (clob_2_value,)]] + + +async def test_7649(async_conn, test_env): + "7649 - test PL/SQL returning LOB data from a function" + clob_format = "Sample data for test 7649 - {}" + num_values = [5, 38, 1549] + pipeline = oracledb.create_pipeline() + for num in num_values: + pipeline.add_callfunc( + "pkg_TestLOBs.GetLOB", + return_type=oracledb.DB_TYPE_CLOB, + parameters=[num, clob_format], + ) + res = await async_conn.run_pipeline(pipeline) + for result, num in zip(res, num_values): + expected_value = clob_format.replace("{}", str(num)) + assert await result.return_value.read() == expected_value From 7451c305ce5b5c5407e5c4e8c4b143d19213ca94 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:45:47 -0700 Subject: [PATCH 13/32] Fix template. --- utils/templates/connect_params.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/templates/connect_params.py b/utils/templates/connect_params.py index ceab8c5e..35f7aeae 100644 --- a/utils/templates/connect_params.py +++ b/utils/templates/connect_params.py @@ -37,16 +37,16 @@ import oracledb +from .base import BaseMetaClass from . import base_impl, utils -class ConnectParams: +class ConnectParams(metaclass=BaseMetaClass): """ Contains all parameters used for establishing a connection to the database. """ - __module__ = oracledb.__name__ __slots__ = ["_impl"] _impl_class = base_impl.ConnectParamsImpl From 30d956eaa293ae4b9a24a77a403a6e0b1621db9f Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:45:59 -0700 Subject: [PATCH 14/32] Remove dead code. --- src/oracledb/impl/thin/connection.pyx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/oracledb/impl/thin/connection.pyx b/src/oracledb/impl/thin/connection.pyx index c83bd620..442c98b7 100644 --- a/src/oracledb/impl/thin/connection.pyx +++ b/src/oracledb/impl/thin/connection.pyx @@ -340,16 +340,6 @@ cdef class BaseThinConnImpl(BaseConnImpl): get_dbobject_type_cache(self._dbobject_type_cache_num) return cache.get_type(conn, name) - def ping(self): - cdef Message message - message = self._create_message(PingMessage) - self._protocol._process_single_message(message) - - def rollback(self): - cdef Message message - message = self._create_message(RollbackMessage) - self._protocol._process_single_message(message) - def set_action(self, str value): self._action = value self._action_modified = True From 306e41b1aaf6f04fef4538cda5fc1999b47a1d84 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 10:46:14 -0700 Subject: [PATCH 15/32] Fixed bug when fetching a timestamp with nanosecond precision into a data frame (#538). --- doc/src/release_notes.rst | 3 ++ src/oracledb/impl/base/converters.pyx | 13 ++++++-- tests/test_9300_dataframe_requested_schema.py | 31 ++++++++++++------- ...t_9400_dataframe_requested_schema_async.py | 31 ++++++++++++------- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 1eef507f..ebbe0794 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -19,6 +19,9 @@ oracledb `3.4.1 `__). #) Fixed bug when adding a call to a PL/SQL function which returns LOBs to a :ref:`pipeline `. #) Fixed bug when using bind variables with scrollable cursors. diff --git a/src/oracledb/impl/base/converters.pyx b/src/oracledb/impl/base/converters.pyx index 27ed64dd..fa4d0adb 100644 --- a/src/oracledb/impl/base/converters.pyx +++ b/src/oracledb/impl/base/converters.pyx @@ -186,10 +186,19 @@ cdef int convert_date_to_arrow_timestamp(ArrowArrayImpl array_impl, cdef: cydatetime.timedelta td cydatetime.datetime dt - int64_t ts + int64_t ts, us dt = convert_date_to_python(buffer) td = dt - EPOCH_DATE - ts = int(cydatetime.total_seconds(td) * array_impl.schema_impl.time_factor) + ts = ( cydatetime.timedelta_days(td)) * (24 * 60 * 60) + \ + cydatetime.timedelta_seconds(td) + ts *= array_impl.schema_impl.time_factor + us = cydatetime.timedelta_microseconds(td) + if array_impl.schema_impl.time_factor == 1_000: + ts += us // 1_000 + elif array_impl.schema_impl.time_factor == 1_000_000: + ts += us + elif array_impl.schema_impl.time_factor != 1: + ts += us * 1_000 array_impl.append_int(ts) diff --git a/tests/test_9300_dataframe_requested_schema.py b/tests/test_9300_dataframe_requested_schema.py index d457ded3..d93627b3 100644 --- a/tests/test_9300_dataframe_requested_schema.py +++ b/tests/test_9300_dataframe_requested_schema.py @@ -28,6 +28,7 @@ import datetime +import oracledb import pyarrow import pytest @@ -281,28 +282,34 @@ def test_9310(dtype, value_is_date, conn): @pytest.mark.parametrize( - "dtype,value_is_date", + "dtype", [ - (pyarrow.date32(), True), - (pyarrow.date64(), True), - (pyarrow.timestamp("s"), False), - (pyarrow.timestamp("us"), False), - (pyarrow.timestamp("ms"), False), - (pyarrow.timestamp("ns"), False), + pyarrow.date32(), + pyarrow.date64(), + pyarrow.timestamp("s"), + pyarrow.timestamp("us"), + pyarrow.timestamp("ms"), + pyarrow.timestamp("ns"), ], ) -def test_9311(dtype, value_is_date, conn): +def test_9311(dtype, conn): "9311 - fetch_df_all() for TIMESTAMP" requested_schema = pyarrow.schema([("TIMESTAMP_COL", dtype)]) - value = datetime.datetime(2025, 1, 15) - statement = "select cast(:1 as timestamp) from dual" + value = datetime.datetime(1974, 4, 4, 0, 57, 54, 15079) + var = conn.cursor().var(oracledb.DB_TYPE_TIMESTAMP) + var.setvalue(0, value) + statement = "select :1 from dual" ora_df = conn.fetch_df_all( - statement, [value], requested_schema=requested_schema + statement, [var], requested_schema=requested_schema ) tab = pyarrow.table(ora_df) assert tab.field("TIMESTAMP_COL").type == dtype - if value_is_date: + if not isinstance(dtype, pyarrow.TimestampType): value = value.date() + elif dtype.unit == "s": + value = value.replace(microsecond=0) + elif dtype.unit == "ms": + value = value.replace(microsecond=(value.microsecond // 1000) * 1000) assert tab["TIMESTAMP_COL"][0].as_py() == value diff --git a/tests/test_9400_dataframe_requested_schema_async.py b/tests/test_9400_dataframe_requested_schema_async.py index 1308b15d..aa69cfdf 100644 --- a/tests/test_9400_dataframe_requested_schema_async.py +++ b/tests/test_9400_dataframe_requested_schema_async.py @@ -28,6 +28,7 @@ import datetime +import oracledb import pyarrow import pytest @@ -298,28 +299,34 @@ async def test_9410(dtype, value_is_date, async_conn): @pytest.mark.parametrize( - "dtype,value_is_date", + "dtype", [ - (pyarrow.date32(), True), - (pyarrow.date64(), True), - (pyarrow.timestamp("s"), False), - (pyarrow.timestamp("us"), False), - (pyarrow.timestamp("ms"), False), - (pyarrow.timestamp("ns"), False), + pyarrow.date32(), + pyarrow.date64(), + pyarrow.timestamp("s"), + pyarrow.timestamp("us"), + pyarrow.timestamp("ms"), + pyarrow.timestamp("ns"), ], ) -async def test_9411(dtype, value_is_date, async_conn): +async def test_9411(dtype, async_conn): "9411 - fetch_df_all() for TIMESTAMP" requested_schema = pyarrow.schema([("TIMESTAMP_COL", dtype)]) - value = datetime.datetime(2025, 1, 15) - statement = "select cast(:1 as timestamp) from dual" + value = datetime.datetime(1974, 4, 4, 0, 57, 54, 15079) + var = async_conn.cursor().var(oracledb.DB_TYPE_TIMESTAMP) + var.setvalue(0, value) + statement = "select :1 from dual" ora_df = await async_conn.fetch_df_all( - statement, [value], requested_schema=requested_schema + statement, [var], requested_schema=requested_schema ) tab = pyarrow.table(ora_df) assert tab.field("TIMESTAMP_COL").type == dtype - if value_is_date: + if not isinstance(dtype, pyarrow.TimestampType): value = value.date() + elif dtype.unit == "s": + value = value.replace(microsecond=0) + elif dtype.unit == "ms": + value = value.replace(microsecond=(value.microsecond // 1000) * 1000) assert tab["TIMESTAMP_COL"][0].as_py() == value From c9ecb6ce9e1aebb106b1f86b21937923b96841a8 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 7 Nov 2025 16:00:52 -0700 Subject: [PATCH 16/32] Fixed bug that failed to handle the KeyboardInterrupt exception correctly when the application caught this exception and then tried to reuse the connection. --- doc/src/release_notes.rst | 3 +++ src/oracledb/impl/thin/protocol.pyx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index ebbe0794..01eeaaf9 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -27,6 +27,9 @@ Thin Mode Changes #) Fixed bug when using bind variables with scrollable cursors. #) Fixed bug when setting ``SOURCE_ROUTE`` on the ``DESCRIPTION`` section of a full connect descriptor instead of the ``ADDRESS_LIST`` section. +#) Fixed bug that failed to handle the KeyboardInterrupt exception correctly + when the application caught this exception and then tried to reuse the + connection. Thick Mode Changes ++++++++++++++++++ diff --git a/src/oracledb/impl/thin/protocol.pyx b/src/oracledb/impl/thin/protocol.pyx index dfcfcad3..c34bcff6 100644 --- a/src/oracledb/impl/thin/protocol.pyx +++ b/src/oracledb/impl/thin/protocol.pyx @@ -460,7 +460,7 @@ cdef class Protocol(BaseProtocol): except MarkerDetected: self._reset() message.process(self._read_buf) - except Exception as e: + except BaseException as e: if not self._in_connect \ and self._write_buf._packet_sent \ and self._read_buf._transport is not None \ From f21d50544439ab41e191b98d79e1acc077d2621b Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Tue, 11 Nov 2025 17:59:26 -0700 Subject: [PATCH 17/32] Preparing to release python-oracledb 3.4.1. --- doc/src/release_notes.rst | 4 ++-- src/oracledb/impl/thick/odpi | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 01eeaaf9..fb0a4fd6 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -13,8 +13,8 @@ Release changes are listed as affecting Thin Mode (the default runtime behavior of python-oracledb), as affecting the optional :ref:`Thick Mode `, or as being 'Common' for changes that impact both modes. -oracledb `3.4.1 `__ (TBD) --------------------------------------------------------------------------------------------- +oracledb `3.4.1 `__ (November 2025) +------------------------------------------------------------------------------------------------------ Thin Mode Changes +++++++++++++++++ diff --git a/src/oracledb/impl/thick/odpi b/src/oracledb/impl/thick/odpi index a98ef338..27928bc2 160000 --- a/src/oracledb/impl/thick/odpi +++ b/src/oracledb/impl/thick/odpi @@ -1 +1 @@ -Subproject commit a98ef3384310081155e753063ef19c3e9abd9c23 +Subproject commit 27928bc299c7d132008406fa86c0982e1481f4ff From d9a78e2a4536f3f6ec09e015af793744875ddd54 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:41:15 -0700 Subject: [PATCH 18/32] Bump version in preparation for new changes. --- doc/src/release_notes.rst | 13 +++++++++++++ src/oracledb/version.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index fb0a4fd6..f9828c89 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -13,6 +13,19 @@ Release changes are listed as affecting Thin Mode (the default runtime behavior of python-oracledb), as affecting the optional :ref:`Thick Mode `, or as being 'Common' for changes that impact both modes. +oracledb `3.4.2 `__ (TBD) +-------------------------------------------------------------------------------------------- + +Thin Mode Changes ++++++++++++++++++ + +Thick Mode Changes +++++++++++++++++++ + +Common Changes +++++++++++++++ + + oracledb `3.4.1 `__ (November 2025) ------------------------------------------------------------------------------------------------------ diff --git a/src/oracledb/version.py b/src/oracledb/version.py index 56f8d3e7..6374d445 100644 --- a/src/oracledb/version.py +++ b/src/oracledb/version.py @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2021, 2025, Oracle and/or its affiliates. +# Copyright (c) 2021, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -30,4 +30,4 @@ # file doc/src/conf.py both reference this file directly. # ----------------------------------------------------------------------------- -__version__ = "3.4.1" +__version__ = "3.4.2" From e1dc207b7ea8d09f9cbc73ec7a8802a6a95e859e Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:41:39 -0700 Subject: [PATCH 19/32] Fixed bug when getting the expiry time of authentication tokens (#548). --- doc/src/release_notes.rst | 4 ++++ src/oracledb/impl/base/connect_params.pyx | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index f9828c89..5e430dbb 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -25,6 +25,10 @@ Thick Mode Changes Common Changes ++++++++++++++ +#) Fixed bug when getting the expiry time of + :ref:`authentication tokens ` + (`issue 548 `__). + oracledb `3.4.1 `__ (November 2025) ------------------------------------------------------------------------------------------------------ diff --git a/src/oracledb/impl/base/connect_params.pyx b/src/oracledb/impl/base/connect_params.pyx index eb06d3f3..76b94d2a 100644 --- a/src/oracledb/impl/base/connect_params.pyx +++ b/src/oracledb/impl/base/connect_params.pyx @@ -284,15 +284,15 @@ cdef class ConnectParamsImpl: Gets the expiry date from the token. """ cdef: - str header_seg - dict header - int num_pad - header_seg = token.split(".")[1] - num_pad = len(header_seg) % 4 - if num_pad != 0: - header_seg += '=' * num_pad - header = json.loads(base64.b64decode(header_seg)) - return datetime.datetime.utcfromtimestamp(header["exp"]) + str payload_segment + dict payload + int pad_needed + payload_segment = token.split(".")[1] + pad_needed = len(payload_segment) % 4 + if pad_needed != 0: + payload_segment += '=' * (4 - pad_needed) + payload = json.loads(base64.urlsafe_b64decode(payload_segment)) + return datetime.datetime.utcfromtimestamp(payload["exp"]) cdef bint _get_uses_drcp(self): """ From 50f061c2721c9462131e0f06ed734b79c71cd49d Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:42:18 -0700 Subject: [PATCH 20/32] Fixed regression with contents of Cursor.description when calling Cursor.parse() with a query that returns LOBs. --- doc/src/release_notes.rst | 2 ++ src/oracledb/impl/base/connection.pyx | 2 ++ tests/test_4300_cursor_other.py | 7 +++++++ tests/test_6300_cursor_other_async.py | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 5e430dbb..7a93b53f 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -28,6 +28,8 @@ Common Changes #) Fixed bug when getting the expiry time of :ref:`authentication tokens ` (`issue 548 `__). +#) Fixed regression with contents of :data:`Cursor.description` when calling + :meth:`Cursor.parse()` with a query that returns LOBs. oracledb `3.4.1 `__ (November 2025) diff --git a/src/oracledb/impl/base/connection.pyx b/src/oracledb/impl/base/connection.pyx index 0c43100b..51c5f4c3 100644 --- a/src/oracledb/impl/base/connection.pyx +++ b/src/oracledb/impl/base/connection.pyx @@ -223,6 +223,8 @@ cdef class BaseConnImpl: cursor_impl.scrollable = scrollable cursor_impl.arraysize = C_DEFAULTS.arraysize cursor_impl.prefetchrows = C_DEFAULTS.prefetchrows + cursor_impl.fetch_lobs = C_DEFAULTS.fetch_lobs + cursor_impl.fetch_decimals = C_DEFAULTS.fetch_decimals return cursor_impl def create_msg_props_impl(self): diff --git a/tests/test_4300_cursor_other.py b/tests/test_4300_cursor_other.py index 99293356..33474f41 100644 --- a/tests/test_4300_cursor_other.py +++ b/tests/test_4300_cursor_other.py @@ -1059,3 +1059,10 @@ def test_4371(cursor): cursor.execute("select :1 from dual", [value], fetch_decimals=True) rows = cursor.fetchall() assert isinstance(rows[0][0], decimal.Decimal) + + +def test_4372(cursor): + "4372 - test cursor.parse() uses oracledb.defaults.fetch_lobs" + cursor.parse("select to_clob('some_value') from dual") + fetch_info = cursor.description[0] + assert fetch_info.type is oracledb.DB_TYPE_CLOB diff --git a/tests/test_6300_cursor_other_async.py b/tests/test_6300_cursor_other_async.py index f0a31c78..14aa39f1 100644 --- a/tests/test_6300_cursor_other_async.py +++ b/tests/test_6300_cursor_other_async.py @@ -961,3 +961,10 @@ async def test_6355(async_cursor): ) rows = await async_cursor.fetchall() assert isinstance(rows[0][0], decimal.Decimal) + + +async def test_6356(async_cursor): + "6356 - test cursor.parse() uses oracledb.defaults.fetch_lobs" + await async_cursor.parse("select to_clob('some_value') from dual") + fetch_info = async_cursor.description[0] + assert fetch_info.type is oracledb.DB_TYPE_CLOB From bb926d15fe96de6297676e0a295893dd1d11cd74 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:42:41 -0700 Subject: [PATCH 21/32] Make sure test dependencies are installed. --- pyproject.toml | 1 + tests/README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c630b8e1..1f960c2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,6 +60,7 @@ test = [ "pandas", "pyarrow", "pytest", + "tox", ] oci_config = ["oci"] oci_auth = ["oci"] diff --git a/tests/README.md b/tests/README.md index b3a1d831..100414b8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,8 +1,8 @@ This directory contains the test suite for python-oracledb. -1. Install pytest and tox: +1. Install packages needed for testing: - python -m pip install pytest tox --upgrade + python -m pip install --upgrade oracledb[test] 2. Set the required database credential and related environment variables documented in [conftest.py][2]. From 4d7bcc3a47928f73d3bba3d28ec7c4a9b52daad3 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:43:00 -0700 Subject: [PATCH 22/32] Fixed bug when a DbObject instance contains an attribute of type SYS.XMLTYPE. --- doc/src/release_notes.rst | 3 +++ src/oracledb/impl/thin/dbobject.pyx | 11 +++++++---- tests/test_2300_object_var.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 7a93b53f..294af534 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -19,6 +19,9 @@ oracledb `3.4.2 ` instance contains an attribute + of type ``SYS.XMLTYPE``. + Thick Mode Changes ++++++++++++++++++ diff --git a/src/oracledb/impl/thin/dbobject.pyx b/src/oracledb/impl/thin/dbobject.pyx index 078eafdd..c4fd6d19 100644 --- a/src/oracledb/impl/thin/dbobject.pyx +++ b/src/oracledb/impl/thin/dbobject.pyx @@ -375,15 +375,18 @@ cdef class ThinDbObjectImpl(BaseDbObjectImpl): else PY_TYPE_LOB return cls._from_impl(lob_impl) elif ora_type_num == ORA_TYPE_NUM_OBJECT: + if metadata.objtype is None: + xml_bytes = buf.read_bytes() + if xml_bytes is None: + return None + xml_buf = DbObjectPickleBuffer.__new__(DbObjectPickleBuffer) + xml_buf._populate_from_bytes(xml_bytes) + return xml_buf.read_xmltype(self.type._conn_impl) is_collection = \ metadata.objtype.is_collection or self.type.is_collection buf.get_is_atomic_null(is_collection, &is_null) if is_null: return None - if metadata.objtype is None: - xml_buf = DbObjectPickleBuffer.__new__(DbObjectPickleBuffer) - xml_buf._populate_from_bytes(buf.read_bytes()) - return xml_buf.read_xmltype(self.type._conn_impl) obj_impl = ThinDbObjectImpl.__new__(ThinDbObjectImpl) obj_impl.type = metadata.objtype if is_collection: diff --git a/tests/test_2300_object_var.py b/tests/test_2300_object_var.py index 8a0009e9..16856b37 100644 --- a/tests/test_2300_object_var.py +++ b/tests/test_2300_object_var.py @@ -994,3 +994,18 @@ def test_2348(conn, test_env): obj.size() with test_env.assert_raises_full_code("DPY-2036"): obj.trim(0) + + +def test_2349(skip_unless_thin_mode, cursor): + "2349 - test fetching an object containing a null XmlType instance" + num_val = 2349 + str_val = "A string for test 2349" + cursor.execute( + f""" + select udt_ObjectWithXmlType({num_val}, null, '{str_val}') from dual + """ + ) + (obj,) = cursor.fetchone() + assert obj.NUMBERVALUE == num_val + assert obj.XMLVALUE is None + assert obj.STRINGVALUE == str_val From 7bf23b6c2061d20358b030104249bd703ac1832e Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:43:28 -0700 Subject: [PATCH 23/32] Fixed bug when calling Cursor.executemany() with all of the values in at least one column being null followed by a second call where at least the first row also has a null value but some of the later values are not null (#291). --- doc/src/release_notes.rst | 5 +++ src/oracledb/impl/base/batch_load_manager.pyx | 3 +- src/oracledb/impl/base/bind_var.pyx | 2 +- tests/test_4000_cursor_executemany.py | 37 ++++++++++++++++++- tests/test_6100_cursor_executemany_async.py | 35 ++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 294af534..c277589c 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -31,6 +31,11 @@ Common Changes #) Fixed bug when getting the expiry time of :ref:`authentication tokens ` (`issue 548 `__). +#) Fixed bug when calling :meth:`Cursor.executemany()` with all of the values + in at least one column being null followed by a second call where at least + the first row also has a null value but some of the later values are not + null + (`issue 291 `__). #) Fixed regression with contents of :data:`Cursor.description` when calling :meth:`Cursor.parse()` with a query that returns LOBs. diff --git a/src/oracledb/impl/base/batch_load_manager.pyx b/src/oracledb/impl/base/batch_load_manager.pyx index 39033730..c51e2e28 100644 --- a/src/oracledb/impl/base/batch_load_manager.pyx +++ b/src/oracledb/impl/base/batch_load_manager.pyx @@ -304,12 +304,13 @@ cdef class FullDataBatchLoadManager(BatchLoadManager): Goes to the next batch of data. """ cdef: - bint defer_type_assignment = (self.offset == 0) + bint defer_type_assignment object row ssize_t i self._calculate_num_rows_in_batch(self.total_num_rows) if self.cursor_impl is not None: self.cursor_impl._reset_bind_vars(self.offset, self.num_rows) + defer_type_assignment = True for i in range(self.num_rows): if i == self.num_rows - 1: defer_type_assignment = False diff --git a/src/oracledb/impl/base/bind_var.pyx b/src/oracledb/impl/base/bind_var.pyx index a3896255..fa61f65d 100644 --- a/src/oracledb/impl/base/bind_var.pyx +++ b/src/oracledb/impl/base/bind_var.pyx @@ -136,7 +136,7 @@ cdef class BindVar: return self.var_impl._check_and_set_value(row_num, value, NULL) self.var_impl._check_and_set_value(row_num, value, &was_set) if was_set: - self.has_value = True + self.has_value = not defer_type_assignment return 0 self.var_impl = None self.var = None diff --git a/tests/test_4000_cursor_executemany.py b/tests/test_4000_cursor_executemany.py index 19e6ef4c..5382b456 100644 --- a/tests/test_4000_cursor_executemany.py +++ b/tests/test_4000_cursor_executemany.py @@ -27,6 +27,7 @@ """ import decimal +import itertools import oracledb import pytest @@ -475,7 +476,7 @@ def test_4030(cursor): @pytest.mark.parametrize("batch_size", [1, 5, 99, 199, 200]) def test_4031(batch_size, conn, cursor, empty_tab, round_trip_checker): - "4030 - test executemany with various batch sizes" + "4031 - test executemany with various batch sizes" rows = [(i + 1, f"String for row {i + 1}") for i in range(200)] cursor.executemany( "insert into TestTempTable (IntCol, StringCol1) values (:1, :2)", @@ -491,3 +492,37 @@ def test_4031(batch_size, conn, cursor, empty_tab, round_trip_checker): "select IntCol, StringCol1 from TestTempTable order by IntCol" ) assert cursor.fetchall() == rows + + +def test_4032(conn, cursor, empty_tab): + "4032 - test consecutive executemany() with all values null in first call" + rows = [(i + 1, None) for i in range(10)] + [ + (i + 11, (i + 11) * 0.25) for i in range(10) + ] + for chunk in itertools.batched(rows, 4): + cursor.executemany( + "insert into TestTempTable (IntCol, NumberCol) values (:1, :2)", + list(chunk), + ) + conn.commit() + cursor.execute( + "select IntCol, NumberCol from TestTempTable order by IntCol" + ) + assert cursor.fetchall() == rows + + +def test_4033(conn, cursor, empty_tab): + "4033 - test batched executemany() with all values null in first chunks" + rows = [(i + 1, None) for i in range(10)] + [ + (i + 11, (i + 11) * 0.25) for i in range(10) + ] + cursor.executemany( + "insert into TestTempTable (IntCol, NumberCol) values (:1, :2)", + rows, + batch_size=4, + ) + conn.commit() + cursor.execute( + "select IntCol, NumberCol from TestTempTable order by IntCol" + ) + assert cursor.fetchall() == rows diff --git a/tests/test_6100_cursor_executemany_async.py b/tests/test_6100_cursor_executemany_async.py index 5fe3983f..7596e153 100644 --- a/tests/test_6100_cursor_executemany_async.py +++ b/tests/test_6100_cursor_executemany_async.py @@ -27,6 +27,7 @@ """ import decimal +import itertools import oracledb import pytest @@ -436,3 +437,37 @@ async def test_6127( "select IntCol, StringCol1 from TestTempTable order by IntCol" ) assert await async_cursor.fetchall() == rows + + +async def test_6128(async_conn, async_cursor, empty_tab): + "6128 - test consecutive executemany() with all values null in first call" + rows = [(i + 1, None) for i in range(10)] + [ + (i + 11, (i + 11) * 0.25) for i in range(10) + ] + for chunk in itertools.batched(rows, 4): + await async_cursor.executemany( + "insert into TestTempTable (IntCol, NumberCol) values (:1, :2)", + list(chunk), + ) + await async_conn.commit() + await async_cursor.execute( + "select IntCol, NumberCol from TestTempTable order by IntCol" + ) + assert await async_cursor.fetchall() == rows + + +async def test_6129(async_conn, async_cursor, empty_tab): + "6129 - test batched executemany() with all values null in first chunks" + rows = [(i + 1, None) for i in range(10)] + [ + (i + 11, (i + 11) * 0.25) for i in range(10) + ] + await async_cursor.executemany( + "insert into TestTempTable (IntCol, NumberCol) values (:1, :2)", + rows, + batch_size=4, + ) + await async_conn.commit() + await async_cursor.execute( + "select IntCol, NumberCol from TestTempTable order by IntCol" + ) + assert await async_cursor.fetchall() == rows From 36f8899fa71ebd4aec80b87f990633e86abc6b95 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:43:56 -0700 Subject: [PATCH 24/32] Added support for ingesting Arrow arrays which only consist of null values (#554). --- doc/src/release_notes.rst | 2 ++ src/oracledb/impl/arrow/schema.pyx | 3 +- src/oracledb/impl/base/converters.pyx | 6 ++-- src/oracledb/impl/base/metadata.pyx | 12 ++++---- tests/test_8900_dataframe_ingestion.py | 30 +++++++++++++++++++- tests/test_9000_dataframe_ingestion_async.py | 30 +++++++++++++++++++- 6 files changed, 73 insertions(+), 10 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index c277589c..8204f3d1 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -36,6 +36,8 @@ Common Changes the first row also has a null value but some of the later values are not null (`issue 291 `__). +#) Added support for ingesting Arrow arrays which only consist of null values + (`issue 554 `__). #) Fixed regression with contents of :data:`Cursor.description` when calling :meth:`Cursor.parse()` with a query that returns LOBs. diff --git a/src/oracledb/impl/arrow/schema.pyx b/src/oracledb/impl/arrow/schema.pyx index b11f095b..b84ded14 100644 --- a/src/oracledb/impl/arrow/schema.pyx +++ b/src/oracledb/impl/arrow/schema.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2025, Oracle and/or its affiliates. +# Copyright (c) 2025, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -181,6 +181,7 @@ cdef class ArrowSchemaImpl: NANOARROW_TYPE_INT64, NANOARROW_TYPE_LARGE_BINARY, NANOARROW_TYPE_LARGE_STRING, + NANOARROW_TYPE_NA, NANOARROW_TYPE_STRING, NANOARROW_TYPE_UINT8, NANOARROW_TYPE_UINT16, diff --git a/src/oracledb/impl/base/converters.pyx b/src/oracledb/impl/base/converters.pyx index fa4d0adb..4aa9dafd 100644 --- a/src/oracledb/impl/base/converters.pyx +++ b/src/oracledb/impl/base/converters.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2024, 2025, Oracle and/or its affiliates. +# Copyright (c) 2024, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -50,7 +50,9 @@ cdef object convert_arrow_to_oracle_data(OracleMetadata metadata, arrow_type = metadata._schema_impl.arrow_type db_type_num = metadata.dbtype.num - if arrow_type in ( + if arrow_type == NANOARROW_TYPE_NA: + data.is_null = True + elif arrow_type in ( NANOARROW_TYPE_INT8, NANOARROW_TYPE_INT16, NANOARROW_TYPE_INT32, diff --git a/src/oracledb/impl/base/metadata.pyx b/src/oracledb/impl/base/metadata.pyx index 049c2bbb..0ad754b1 100644 --- a/src/oracledb/impl/base/metadata.pyx +++ b/src/oracledb/impl/base/metadata.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2024, 2025, Oracle and/or its affiliates. +# Copyright (c) 2024, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -152,9 +152,11 @@ cdef class OracleMetadata: uint32_t db_type_num = self.dbtype.num bint ok = False - if arrow_type in (NANOARROW_TYPE_BINARY, - NANOARROW_TYPE_FIXED_SIZE_BINARY, - NANOARROW_TYPE_LARGE_BINARY): + if arrow_type == NANOARROW_TYPE_NA: + ok = True + elif arrow_type in (NANOARROW_TYPE_BINARY, + NANOARROW_TYPE_FIXED_SIZE_BINARY, + NANOARROW_TYPE_LARGE_BINARY): if db_type_num in (DB_TYPE_NUM_RAW, DB_TYPE_NUM_LONG_RAW): ok = True elif arrow_type == NANOARROW_TYPE_BOOL: @@ -326,7 +328,7 @@ cdef class OracleMetadata: NANOARROW_TYPE_UINT64, ): metadata.dbtype = DB_TYPE_NUMBER - elif arrow_type == NANOARROW_TYPE_STRING: + elif arrow_type in (NANOARROW_TYPE_STRING, NANOARROW_TYPE_NA): metadata.dbtype = DB_TYPE_VARCHAR elif arrow_type in (NANOARROW_TYPE_BINARY, NANOARROW_TYPE_FIXED_SIZE_BINARY): diff --git a/tests/test_8900_dataframe_ingestion.py b/tests/test_8900_dataframe_ingestion.py index eccce667..4ad86435 100644 --- a/tests/test_8900_dataframe_ingestion.py +++ b/tests/test_8900_dataframe_ingestion.py @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2025, Oracle and/or its affiliates. +# Copyright (c) 2025, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -1001,3 +1001,31 @@ def test_8922(batch_size, conn, cursor, empty_tab, round_trip_checker): conn.commit() cursor.execute("select Id, FirstName from TestDataFrame order by Id") assert cursor.fetchall() == rows + + +def test_8923(conn, cursor, empty_tab): + "8923 - test ingestion with a column containing only null values" + names = ["Id", "DateOfBirth"] + values = [None] * 3 + arrays = [ + pyarrow.array([1, 2, 3], pyarrow.int8()), + pyarrow.array(values, pyarrow.null()), + ] + df = pyarrow.table(arrays, names) + cursor.executemany( + """ + insert into TestDataFrame (Id, DateOfBirth) + values (:1, :2) + """, + df, + ) + conn.commit() + cursor.execute( + """ + select DateOfBirth + from TestDataFrame + order by Id + """ + ) + fetched_values = [d for d, in cursor] + assert fetched_values == values diff --git a/tests/test_9000_dataframe_ingestion_async.py b/tests/test_9000_dataframe_ingestion_async.py index 43d4277b..0baad8ac 100644 --- a/tests/test_9000_dataframe_ingestion_async.py +++ b/tests/test_9000_dataframe_ingestion_async.py @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2025, Oracle and/or its affiliates. +# Copyright (c) 2025, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -1019,3 +1019,31 @@ async def test_9022( "select Id, FirstName from TestDataFrame order by Id" ) assert await async_cursor.fetchall() == rows + + +async def test_9023(async_conn, async_cursor, empty_tab): + "9023 - test ingestion with a column containing only null values" + names = ["Id", "DateOfBirth"] + values = [None] * 3 + arrays = [ + pyarrow.array([1, 2, 3], pyarrow.int8()), + pyarrow.array(values, pyarrow.null()), + ] + df = pyarrow.table(arrays, names) + await async_cursor.executemany( + """ + insert into TestDataFrame (Id, DateOfBirth) + values (:1, :2) + """, + df, + ) + await async_conn.commit() + await async_cursor.execute( + """ + select DateOfBirth + from TestDataFrame + order by Id + """ + ) + fetched_values = [d async for d, in async_cursor] + assert fetched_values == values From 40200bfa1cb9dde0977a509c84cfdde66f144358 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:44:25 -0700 Subject: [PATCH 25/32] Adjusted code and tests to be capable of being run in environments other than CPython. --- doc/src/release_notes.rst | 2 + src/oracledb/impl/base/encoders.pyx | 11 +- tests/conftest.py | 33 ++- tests/test_1100_connection.py | 250 ++++++++++--------- tests/test_1300_cursor_var.py | 31 +-- tests/test_1700_error.py | 20 +- tests/test_1900_lob_var.py | 2 +- tests/test_2300_object_var.py | 8 +- tests/test_2400_pool.py | 108 +++++--- tests/test_2700_aq_dbobject.py | 179 ++++++------- tests/test_2800_aq_bulk.py | 40 +-- tests/test_3000_subscription.py | 114 ++++----- tests/test_3800_typehandler.py | 50 ++-- tests/test_4300_cursor_other.py | 42 ++-- tests/test_5700_lob_var_async.py | 4 +- tests/test_6600_defaults.py | 67 ++--- tests/test_7300_unsupported_features_thin.py | 2 + tests/test_7800_aq_raw.py | 124 ++++----- tests/test_8300_aq_json.py | 60 ++--- 19 files changed, 616 insertions(+), 531 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 8204f3d1..51e9bce5 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -40,6 +40,8 @@ Common Changes (`issue 554 `__). #) Fixed regression with contents of :data:`Cursor.description` when calling :meth:`Cursor.parse()` with a query that returns LOBs. +#) Adjusted code and tests to be capable of being run in environments other + than CPython. oracledb `3.4.1 `__ (November 2025) diff --git a/src/oracledb/impl/base/encoders.pyx b/src/oracledb/impl/base/encoders.pyx index aed7e420..fcb196c4 100644 --- a/src/oracledb/impl/base/encoders.pyx +++ b/src/oracledb/impl/base/encoders.pyx @@ -121,9 +121,14 @@ cdef inline void encode_date(char_type *buf, object value): buf[1] = ((year % 100) + 100) buf[2] = cydatetime.PyDateTime_GET_MONTH(value) buf[3] = cydatetime.PyDateTime_GET_DAY(value) - buf[4] = cydatetime.PyDateTime_DATE_GET_HOUR(value) + 1 - buf[5] = cydatetime.PyDateTime_DATE_GET_MINUTE(value) + 1 - buf[6] = cydatetime.PyDateTime_DATE_GET_SECOND(value) + 1 + if cydatetime.PyDateTime_Check(value): + buf[4] = cydatetime.PyDateTime_DATE_GET_HOUR(value) + 1 + buf[5] = cydatetime.PyDateTime_DATE_GET_MINUTE(value) + 1 + buf[6] = cydatetime.PyDateTime_DATE_GET_SECOND(value) + 1 + else: + buf[4] = 1 + buf[5] = 1 + buf[6] = 1 cdef inline void encode_interval_ds(char_type *buf, object value): diff --git a/tests/conftest.py b/tests/conftest.py index b5e784ca..42673e49 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -75,6 +75,7 @@ import platform import secrets import string +import sys import numpy import oracledb @@ -259,19 +260,19 @@ def _initialize(self): # establish a connection to determine the remaining information params = self.get_connect_params() - conn = oracledb.connect(dsn=self.connect_string, params=params) - version_parts = conn.version.split(".")[:2] - self.server_version = tuple(int(s) for s in version_parts) - self.is_drcp = self._is_drcp() - self.is_implicit_pooling = self._is_implicit_pooling() - self.is_on_oracle_cloud = self._is_on_oracle_cloud(conn) - self.charset = self._get_charset(conn) - self.charset_ratios = self._get_charset_ratios(conn) - self.sleep_proc_name = ( - "dbms_session.sleep" - if self.server_version >= (18, 0) - else "dbms_lock.sleep" - ) + with oracledb.connect(dsn=self.connect_string, params=params) as conn: + version_parts = conn.version.split(".")[:2] + self.server_version = tuple(int(s) for s in version_parts) + self.is_drcp = self._is_drcp() + self.is_implicit_pooling = self._is_implicit_pooling() + self.is_on_oracle_cloud = self._is_on_oracle_cloud(conn) + self.charset = self._get_charset(conn) + self.charset_ratios = self._get_charset_ratios(conn) + self.sleep_proc_name = ( + "dbms_session.sleep" + if self.server_version >= (18, 0) + else "dbms_lock.sleep" + ) # mark environment as fully initialized self.initialized = True @@ -990,6 +991,12 @@ def skip_unless_vectors_supported(test_env): pytest.skip("no vector support") +@pytest.fixture +def skip_unless_refcounting(): + if sys.implementation.name in ("graalpy", "pypy"): + pytest.skip("needs interpreter with refcounting") + + @pytest.fixture def soda_db(conn, test_env): """ diff --git a/tests/test_1100_connection.py b/tests/test_1100_connection.py index 6e208f2c..f238b491 100644 --- a/tests/test_1100_connection.py +++ b/tests/test_1100_connection.py @@ -42,11 +42,11 @@ def _verify_connect_arg(test_env, arg_name, arg_value, sql): """ args = {} args[arg_name] = arg_value - conn = test_env.get_connection(**args) - cursor = conn.cursor() - cursor.execute(sql) - (fetched_value,) = cursor.fetchone() - assert fetched_value == arg_value + with test_env.get_connection(**args) as conn: + cursor = conn.cursor() + cursor.execute(sql) + (fetched_value,) = cursor.fetchone() + assert fetched_value == arg_value def test_1100(test_env, conn): @@ -64,14 +64,14 @@ def test_1101(skip_if_drcp, test_env): (namespace, "ATTR2", "VALUE2"), (namespace, "ATTR3", "VALUE3"), ] - conn = test_env.get_connection(appcontext=app_context_entries) - cursor = conn.cursor() - for namespace, name, value in app_context_entries: - cursor.execute( - "select sys_context(:1, :2) from dual", (namespace, name) - ) - (actual_value,) = cursor.fetchone() - assert actual_value == value + with test_env.get_connection(appcontext=app_context_entries) as conn: + cursor = conn.cursor() + for namespace, name, value in app_context_entries: + cursor.execute( + "select sys_context(:1, :2) from dual", (namespace, name) + ) + (actual_value,) = cursor.fetchone() + assert actual_value == value def test_1102(test_env): @@ -120,18 +120,22 @@ def test_1103(conn, test_env): def test_1104(test_env): "1104 - test use of autocommit" - conn = test_env.get_connection() - cursor = conn.cursor() - other_conn = test_env.get_connection() - other_cursor = other_conn.cursor() - cursor.execute("truncate table TestTempTable") - cursor.execute("insert into TestTempTable (IntCol) values (1)") - other_cursor.execute("select IntCol from TestTempTable") - assert other_cursor.fetchall() == [] - conn.autocommit = True - cursor.execute("insert into TestTempTable (IntCol) values (2)") - other_cursor.execute("select IntCol from TestTempTable order by IntCol") - assert other_cursor.fetchall() == [(1,), (2,)] + with ( + test_env.get_connection() as conn, + test_env.get_connection() as other_conn, + ): + cursor = conn.cursor() + other_cursor = other_conn.cursor() + cursor.execute("truncate table TestTempTable") + cursor.execute("insert into TestTempTable (IntCol) values (1)") + other_cursor.execute("select IntCol from TestTempTable") + assert other_cursor.fetchall() == [] + conn.autocommit = True + cursor.execute("insert into TestTempTable (IntCol) values (2)") + other_cursor.execute( + "select IntCol from TestTempTable order by IntCol" + ) + assert other_cursor.fetchall() == [(1,), (2,)] def test_1105(test_env): @@ -160,8 +164,8 @@ def test_1107(skip_if_drcp, conn, test_env): sys_random.choice(string.ascii_letters) for i in range(20) ) conn.changepassword(test_env.main_password, new_password) - conn = test_env.get_connection(password=new_password) - conn.changepassword(new_password, test_env.main_password) + with test_env.get_connection(password=new_password) as conn: + conn.changepassword(new_password, test_env.main_password) def test_1108(skip_if_drcp, conn, test_env): @@ -188,7 +192,8 @@ def test_1109(skip_if_drcp, conn, test_env): new_password = "".join(chars) conn.changepassword(test_env.main_password, new_password) try: - test_env.get_connection(password=new_password) + with test_env.get_connection(password=new_password): + pass finally: conn.changepassword(new_password, test_env.main_password) @@ -231,32 +236,36 @@ def test_1112(conn): def test_1113(test_env): "1113 - connection rolls back before close" - conn = test_env.get_connection() - cursor = conn.cursor() - cursor.execute("truncate table TestTempTable") - other_conn = test_env.get_connection() - other_cursor = other_conn.cursor() - other_cursor.execute("insert into TestTempTable (IntCol) values (1)") - other_cursor.close() - other_conn.close() - cursor.execute("select count(*) from TestTempTable") - (count,) = cursor.fetchone() - assert count == 0 + with ( + test_env.get_connection() as conn, + test_env.get_connection() as other_conn, + ): + cursor = conn.cursor() + cursor.execute("truncate table TestTempTable") + other_cursor = other_conn.cursor() + other_cursor.execute("insert into TestTempTable (IntCol) values (1)") + other_cursor.close() + other_conn.close() + cursor.execute("select count(*) from TestTempTable") + (count,) = cursor.fetchone() + assert count == 0 def test_1114(test_env): "1114 - connection rolls back before destruction" - conn = test_env.get_connection() - cursor = conn.cursor() - cursor.execute("truncate table TestTempTable") - other_conn = test_env.get_connection() - other_cursor = other_conn.cursor() - other_cursor.execute("insert into TestTempTable (IntCol) values (1)") - del other_cursor - del other_conn - cursor.execute("select count(*) from TestTempTable") - (count,) = cursor.fetchone() - assert count == 0 + with ( + test_env.get_connection() as conn, + test_env.get_connection() as other_conn, + ): + cursor = conn.cursor() + cursor.execute("truncate table TestTempTable") + other_cursor = other_conn.cursor() + other_cursor.execute("insert into TestTempTable (IntCol) values (1)") + del other_cursor + del other_conn + cursor.execute("select count(*) from TestTempTable") + (count,) = cursor.fetchone() + assert count == 0 def test_1115(test_env): @@ -298,11 +307,11 @@ def test_1117(test_env): cursor.execute("insert into TestTempTable (IntCol) values (2)") with test_env.assert_raises_full_code("DPY-1001"): conn.ping() - conn = test_env.get_connection() - cursor = conn.cursor() - cursor.execute("select count(*) from TestTempTable") - (count,) = cursor.fetchone() - assert count == 1 + with test_env.get_connection() as conn: + cursor = conn.cursor() + cursor.execute("select count(*) from TestTempTable") + (count,) = cursor.fetchone() + assert count == 1 def test_1118(conn, test_env): @@ -536,27 +545,32 @@ def test_1127(skip_if_drcp, conn, test_env): new_password = "".join( sys_random.choice(string.ascii_letters) for i in range(20) ) - conn = test_env.get_connection(newpassword=new_password) - conn = test_env.get_connection(password=new_password) - conn.changepassword(new_password, test_env.main_password) + with test_env.get_connection(newpassword=new_password): + pass + with test_env.get_connection(password=new_password) as conn: + conn.changepassword(new_password, test_env.main_password) def test_1128(test_env): "1128 - test use of autocommit during reexecute" sql = "insert into TestTempTable (IntCol, StringCol1) values (:1, :2)" data_to_insert = [(1, "Test String #1"), (2, "Test String #2")] - conn = test_env.get_connection() - cursor = conn.cursor() - other_conn = test_env.get_connection() - other_cursor = other_conn.cursor() - cursor.execute("truncate table TestTempTable") - cursor.execute(sql, data_to_insert[0]) - other_cursor.execute("select IntCol, StringCol1 from TestTempTable") - assert other_cursor.fetchall() == [] - conn.autocommit = True - cursor.execute(sql, data_to_insert[1]) - other_cursor.execute("select IntCol, StringCol1 from TestTempTable") - assert other_cursor.fetchall() == data_to_insert + with test_env.get_connection() as conn: + cursor = conn.cursor() + with test_env.get_connection() as other_conn: + other_cursor = other_conn.cursor() + cursor.execute("truncate table TestTempTable") + cursor.execute(sql, data_to_insert[0]) + other_cursor.execute( + "select IntCol, StringCol1 from TestTempTable" + ) + assert other_cursor.fetchall() == [] + conn.autocommit = True + cursor.execute(sql, data_to_insert[1]) + other_cursor.execute( + "select IntCol, StringCol1 from TestTempTable" + ) + assert other_cursor.fetchall() == data_to_insert def test_1129(conn, test_env): @@ -602,12 +616,13 @@ def test_1132(test_env): class MyConnection(oracledb.Connection): pass - conn = test_env.get_connection(conn_class=MyConnection) - qual_name = conn.__class__.__qualname__ - expected_value = f"<{__name__}.{qual_name} to {conn.username}@{conn.dsn}>" - assert repr(conn) == expected_value + with test_env.get_connection(conn_class=MyConnection) as conn: + qual_name = conn.__class__.__qualname__ + expected_value = ( + f"<{__name__}.{qual_name} to {conn.username}@{conn.dsn}>" + ) + assert repr(conn) == expected_value - conn.close() expected_value = f"<{__name__}.{qual_name} disconnected>" assert repr(conn) == expected_value @@ -664,20 +679,19 @@ def test_1137(skip_if_drcp, skip_unless_long_passwords_supported, test_env): if test_env.is_on_oracle_cloud: pytest.skip("passwords on Oracle Cloud are strictly controlled") - conn = test_env.get_connection() - original_password = test_env.main_password - new_password_32 = "a" * 32 - conn.changepassword(original_password, new_password_32) - conn = test_env.get_connection(password=new_password_32) - - new_password_1024 = "a" * 1024 - conn.changepassword(new_password_32, new_password_1024) - conn = test_env.get_connection(password=new_password_1024) - conn.changepassword(new_password_1024, original_password) + with test_env.get_connection() as conn: + original_password = test_env.main_password + new_password_32 = "a" * 32 + conn.changepassword(original_password, new_password_32) + with test_env.get_connection(password=new_password_32) as conn: + new_password_1024 = "a" * 1024 + conn.changepassword(new_password_32, new_password_1024) + with test_env.get_connection(password=new_password_1024) as conn: + conn.changepassword(new_password_1024, original_password) - new_password_1025 = "a" * 1025 - with test_env.assert_raises_full_code("ORA-28218", "ORA-00972"): - conn.changepassword(original_password, new_password_1025) + new_password_1025 = "a" * 1025 + with test_env.assert_raises_full_code("ORA-28218", "ORA-00972"): + conn.changepassword(original_password, new_password_1025) def test_1138(conn): @@ -729,16 +743,16 @@ def test_1142(conn): def test_1143(test_env): "1143 - test connecting with a proxy user" - conn = test_env.get_connection(proxy_user=test_env.proxy_user) - assert conn.username == test_env.main_user - assert conn.proxy_user == test_env.proxy_user + with test_env.get_connection(proxy_user=test_env.proxy_user) as conn: + assert conn.username == test_env.main_user + assert conn.proxy_user == test_env.proxy_user def test_1144(skip_unless_thin_mode, conn, test_env): "1144 - test connection.sdu" sdu = random.randint(512, conn.sdu) - conn = test_env.get_connection(sdu=sdu) - assert conn.sdu == sdu + with test_env.get_connection(sdu=sdu) as conn: + assert conn.sdu == sdu def test_1145(test_env): @@ -824,8 +838,8 @@ def hook(passed_protocol, passed_protocol_arg, passed_params): try: oracledb.register_protocol(protocol, hook) - oracledb.connect(dsn=connect_string, params=params) - assert params.sdu == sdu + with oracledb.connect(dsn=connect_string, params=params): + assert params.sdu == sdu finally: oracledb.register_protocol(protocol, None) @@ -847,13 +861,13 @@ def test_1154(conn, test_env): def test_1155(test_env): "1155 - test connect() with edition" edition = test_env.edition_name - conn = test_env.get_connection(edition=edition) - cursor = conn.cursor() - cursor.execute( - "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual" - ) - assert cursor.fetchone()[0] == edition.upper() - assert conn.edition == edition + with test_env.get_connection(edition=edition) as conn: + cursor = conn.cursor() + cursor.execute( + "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual" + ) + assert cursor.fetchone()[0] == edition.upper() + assert conn.edition == edition def test_1156(conn, test_env): @@ -866,13 +880,13 @@ def hook(params): try: oracledb.register_params_hook(hook) - conn = test_env.get_connection() - assert conn.stmtcachesize == stmtcachesize + with test_env.get_connection() as conn: + assert conn.stmtcachesize == stmtcachesize finally: oracledb.unregister_params_hook(hook) - conn = test_env.get_connection() - assert conn.stmtcachesize == orig_stmtcachesize + with test_env.get_connection() as conn: + assert conn.stmtcachesize == orig_stmtcachesize def test_1157(test_env, conn): @@ -887,18 +901,18 @@ def hook2(params): def hook3(params): order.append("third") - test_env.get_connection() - oracledb.register_params_hook(hook1) - oracledb.register_params_hook(hook2) - oracledb.register_params_hook(hook3) - try: - order = [] - test_env.get_connection() - assert order == ["first", "second", "third"] - finally: - oracledb.unregister_params_hook(hook1) - oracledb.unregister_params_hook(hook2) - oracledb.unregister_params_hook(hook3) + with test_env.get_connection(): + oracledb.register_params_hook(hook1) + oracledb.register_params_hook(hook2) + oracledb.register_params_hook(hook3) + try: + order = [] + with test_env.get_connection(): + assert order == ["first", "second", "third"] + finally: + oracledb.unregister_params_hook(hook1) + oracledb.unregister_params_hook(hook2) + oracledb.unregister_params_hook(hook3) def test_1158(conn, test_env): diff --git a/tests/test_1300_cursor_var.py b/tests/test_1300_cursor_var.py index f75b0465..5308d919 100644 --- a/tests/test_1300_cursor_var.py +++ b/tests/test_1300_cursor_var.py @@ -273,18 +273,18 @@ def cursor(self): Counter.cursor_created() return super().cursor() - conn = test_env.get_connection(conn_class=MyConnection) - cursor = conn.cursor() - cursor.execute( - """ - select - cursor(select 1 from dual), - cursor(select 2 from dual) - from dual - """ - ) - cursor.fetchall() - assert Counter.num_cursors_created == 3 + with test_env.get_connection(conn_class=MyConnection) as conn: + cursor = conn.cursor() + cursor.execute( + """ + select + cursor(select 1 from dual), + cursor(select 2 from dual) + from dual + """ + ) + cursor.fetchall() + assert Counter.num_cursors_created == 3 def test_1312(conn): @@ -461,9 +461,10 @@ def test_1319(cursor, test_env): :cursor := t_Cursor; end; """ - ref_cursor = test_env.get_connection().cursor() - with test_env.assert_raises_full_code("DPY-3027"): - cursor.execute(sql, [ref_cursor]) + with test_env.get_connection() as conn: + ref_cursor = conn.cursor() + with test_env.assert_raises_full_code("DPY-3027"): + cursor.execute(sql, [ref_cursor]) def test_1320(conn): diff --git a/tests/test_1700_error.py b/tests/test_1700_error.py index aea7873a..bc2e579c 100644 --- a/tests/test_1700_error.py +++ b/tests/test_1700_error.py @@ -207,13 +207,13 @@ def test_1708(cursor): def test_1709(skip_if_drcp, conn, test_env): "1709 - error from killed connection is deemed recoverable" - admin_conn = test_env.get_admin_connection() - conn = test_env.get_connection() - sid, serial = test_env.get_sid_serial(conn) - with admin_conn.cursor() as admin_cursor: - sql = f"alter system kill session '{sid},{serial}'" - admin_cursor.execute(sql) - with test_env.assert_raises_full_code("DPY-4011") as excinfo: - with conn.cursor() as cursor: - cursor.execute("select user from dual") - assert excinfo.error_obj.isrecoverable + with test_env.get_admin_connection() as admin_conn: + conn = test_env.get_connection() + sid, serial = test_env.get_sid_serial(conn) + with admin_conn.cursor() as admin_cursor: + sql = f"alter system kill session '{sid},{serial}'" + admin_cursor.execute(sql) + with test_env.assert_raises_full_code("DPY-4011") as excinfo: + with conn.cursor() as cursor: + cursor.execute("select user from dual") + assert excinfo.error_obj.isrecoverable diff --git a/tests/test_1900_lob_var.py b/tests/test_1900_lob_var.py index cc5140e6..debaa612 100644 --- a/tests/test_1900_lob_var.py +++ b/tests/test_1900_lob_var.py @@ -411,7 +411,7 @@ def test_1917(cursor, test_env): _test_lob_operations(cursor, test_env, "NCLOB") -def test_1918(skip_if_implicit_pooling, conn, cursor): +def test_1918(skip_if_implicit_pooling, skip_unless_refcounting, conn, cursor): "1918 - test temporary LOBs" cursor.execute("select sys_context('USERENV', 'SID') from dual") (sid,) = cursor.fetchone() diff --git a/tests/test_2300_object_var.py b/tests/test_2300_object_var.py index 16856b37..bcd01a2a 100644 --- a/tests/test_2300_object_var.py +++ b/tests/test_2300_object_var.py @@ -863,11 +863,11 @@ def test_2340(conn, cursor): def test_2341(test_env): "2341 - test insufficient privileges for gettype()" main_user = test_env.main_user.upper() - conn = test_env.get_connection( + with test_env.get_connection( user=test_env.proxy_user, password=test_env.proxy_password - ) - with test_env.assert_raises_full_code("DPY-2035"): - conn.gettype(f"{main_user}.UDT_OBJECTARRAY") + ) as conn: + with test_env.assert_raises_full_code("DPY-2035"): + conn.gettype(f"{main_user}.UDT_OBJECTARRAY") def test_2342(conn, cursor, test_env): diff --git a/tests/test_2400_pool.py b/tests/test_2400_pool.py index f81adfee..0b2577ef 100644 --- a/tests/test_2400_pool.py +++ b/tests/test_2400_pool.py @@ -26,6 +26,7 @@ 2400 - Module for testing pools """ +import contextlib import re import threading @@ -141,6 +142,7 @@ def _perform_reconfigure_test( expected_args = creation_args.copy() expected_args.update(reconfigure_args) assert actual_args == expected_args + pool.close() def _verify_connection(conn, expected_user, expected_proxy_user=None): @@ -200,6 +202,7 @@ def test_2400(test_env): assert pool.thin == (not test_env.use_thick_mode) assert pool.timeout == 0 assert pool.username == test_env.main_user + pool.close() def test_2401(skip_unless_thick_mode, test_env): @@ -210,6 +213,7 @@ def test_2401(skip_unless_thick_mode, test_env): assert pool.homogeneous, "homogeneous should be True by default" with test_env.assert_raises_full_code("DPI-1012"): pool.acquire(user="missing_proxyuser") + pool.close() pool = test_env.get_pool( min=2, max=8, @@ -224,6 +228,7 @@ def test_2401(skip_unless_thick_mode, test_env): (user,) = cursor.fetchone() assert user == test_env.proxy_user.upper() conn.close() + pool.close() def test_2402(test_env): @@ -252,6 +257,7 @@ def test_2402(test_env): pool.soda_metadata_cache = True assert pool.soda_metadata_cache pytest.raises(TypeError, setattr, pool, "soda_metadata_cache", 22) + pool.close() def test_2403(test_env): @@ -263,6 +269,8 @@ def test_2403(test_env): cursor.execute("insert into TestTempTable (IntCol) values (1)") cursor.close() pool.release(conn) + pool.close() + pool = test_env.get_pool(getmode=oracledb.POOL_GETMODE_WAIT) conn = pool.acquire() cursor = conn.cursor() @@ -270,6 +278,7 @@ def test_2403(test_env): (count,) = cursor.fetchone() assert count == 0 conn.close() + pool.close() def test_2404(test_env): @@ -284,6 +293,7 @@ def test_2404(test_env): thread.start() for thread in threads: thread.join() + pool.close() def test_2405(test_env): @@ -300,6 +310,7 @@ def test_2405(test_env): thread.start() for thread in threads: thread.join() + pool.close() def test_2406(skip_if_drcp, test_env): @@ -336,6 +347,7 @@ def test_2406(skip_if_drcp, test_env): assert result is None cursor.close() pool.release(conn) + pool.close() def test_2407(skip_if_drcp, skip_unless_thick_mode, test_env): @@ -349,7 +361,8 @@ def test_2407(skip_if_drcp, skip_unless_thick_mode, test_env): ) assert pool.homogeneous == 0 conn = pool.acquire() - _verify_connection(pool.acquire(), test_env.main_user) + with pool.acquire() as conn2: + _verify_connection(conn2, test_env.main_user) conn.close() conn = pool.acquire(test_env.main_user, test_env.main_password) _verify_connection(conn, test_env.main_user) @@ -363,6 +376,7 @@ def test_2407(skip_if_drcp, skip_unless_thick_mode, test_env): assert conn.proxy_user == test_env.proxy_user _verify_connection(conn, test_env.proxy_user, test_env.main_user) conn.close() + pool.close() def test_2408(skip_if_drcp, skip_unless_thick_mode, test_env): @@ -385,6 +399,8 @@ def test_2408(skip_if_drcp, skip_unless_thick_mode, test_env): user_str = f"{test_env.main_user}[{test_env.proxy_user}]" conn = pool.acquire(user_str, test_env.main_password) _verify_connection(conn, test_env.proxy_user, test_env.main_user) + conn.close() + pool.close() def test_2409(skip_unless_thick_mode, test_env): @@ -398,6 +414,7 @@ def test_2409(skip_unless_thick_mode, test_env): ) with test_env.assert_raises_full_code("ORA-01017"): pool.acquire(test_env.proxy_user, "this is the wrong password") + pool.close() def test_2410(skip_unless_thick_mode, test_env): @@ -424,6 +441,7 @@ def test_2410(skip_unless_thick_mode, test_env): conn = pool.acquire(tag=tag_utc) assert conn.tag == tag_utc conn.close() + pool.close() def test_2411(skip_unless_thick_mode, test_env): @@ -472,6 +490,7 @@ def test_2411(skip_unless_thick_mode, test_env): expected_results = list(zip(tags, actual_tags)) assert results == expected_results conn.close() + pool.close() def test_2412(skip_unless_thick_mode, test_env): @@ -482,6 +501,8 @@ def test_2412(skip_unless_thick_mode, test_env): if test_env.has_client_version(12, 2): with test_env.assert_raises_full_code("ORA-24488"): pool.release(conn, tag="INVALID_TAG") + pool.close(force=True) + conn.close() def test_2413(test_env): @@ -501,6 +522,7 @@ def test_2413(test_env): conn.close() assert pool.busy == 0 assert pool.opened == 3 + pool.close() def test_2414(test_env): @@ -516,6 +538,7 @@ def test_2414(test_env): conn3 = pool.acquire(purity=oracledb.ATTR_PURITY_NEW) assert pool.opened == 2, "opened (2)" pool.release(conn3) + pool.close() def test_2415(skip_unless_thick_mode, test_env): @@ -594,6 +617,7 @@ def test_2417(skip_unless_thick_mode, test_env): cursor.execute("select to_char(current_date) from dual") (result,) = cursor.fetchone() assert callback_obj.session_called + pool.close() def test_2418(test_env): @@ -612,6 +636,7 @@ def test_2419(test_env): with pool.acquire(): with test_env.assert_raises_full_code("DPY-1005"): pool.close() + pool.close() def test_2420(test_env): @@ -644,6 +669,7 @@ def test_2422(test_env): pool.getmode = oracledb.POOL_GETMODE_NOWAIT with test_env.assert_raises_full_code("DPY-4005"): pool.acquire() + pool.close() def test_2423(test_env): @@ -667,6 +693,7 @@ def session_callback(cls, conn, requested_tag): with pool.acquire(), pool.acquire(): pass assert Counter.num_calls == 2 + pool.close() def test_2424(skip_if_drcp, admin_conn, test_env): @@ -700,6 +727,7 @@ def test_2424(skip_if_drcp, admin_conn, test_env): assert user == test_env.main_user.upper() conn.close() assert pool.opened == 2 + pool.close() def test_2425(test_env): @@ -710,6 +738,7 @@ def test_2425(test_env): cursor.execute("select user from dual") (result,) = cursor.fetchone() assert result == test_env.main_user.upper() + pool.close() def test_2426(test_env): @@ -721,13 +750,16 @@ def test_2426(test_env): with pool.acquire() as conn: typ = conn.gettype("UDT_OBJECTARRAY") assert typ.name == "UDT_OBJECTARRAY" + pool.close() def test_2427(test_env): "2427 - test creating a pool using a proxy user" user_str = f"{test_env.main_user}[{test_env.proxy_user}]" pool = test_env.get_pool(user=user_str) - _verify_connection(pool.acquire(), test_env.proxy_user, test_env.main_user) + with pool.acquire() as conn: + _verify_connection(conn, test_env.proxy_user, test_env.main_user) + pool.close() def test_2428(skip_if_drcp, test_env): @@ -736,16 +768,14 @@ def test_2428(skip_if_drcp, test_env): min=5, max=10, increment=1, getmode=oracledb.POOL_GETMODE_WAIT ) sql = "select sys_context('userenv', 'sid') from dual" - conns = [pool.acquire() for i in range(3)] - sids = [conn.cursor().execute(sql).fetchone()[0] for conn in conns] + with contextlib.ExitStack() as stack: + conns = [stack.enter_context(pool.acquire()) for _ in range(3)] + sids = [conn.cursor().execute(sql).fetchone()[0] for conn in conns] - conns[1].close() - conns[2].close() - conns[0].close() - - conn = pool.acquire() - sid = conn.cursor().execute(sql).fetchone()[0] - assert sid == sids[0], "not LIFO" + with pool.acquire() as conn: + sid = conn.cursor().execute(sql).fetchone()[0] + assert sid == sids[0], "not LIFO" + pool.close() def test_2429(test_env): @@ -754,6 +784,7 @@ def test_2429(test_env): assert pool.increment == 1 with pool.acquire(), pool.acquire(): pass + pool.close() def test_2430(test_env): @@ -762,6 +793,7 @@ def test_2430(test_env): assert pool.increment == 0 with pool.acquire(): pass + pool.close() def test_2431(test_env): @@ -781,6 +813,7 @@ def test_2431(test_env): next_sid_serial = test_env.get_sid_serial(conn) assert next_sid_serial == sid_serial assert pool.opened == 1 + pool.close() def test_2432(test_env): @@ -794,6 +827,7 @@ def test_2433(test_env): pool = test_env.get_pool() pytest.raises(TypeError, pool.release, ["invalid connection"]) pytest.raises(TypeError, pool.drop, ["invalid connection"]) + pool.close() def test_2434(test_env): @@ -811,6 +845,7 @@ class MyConnection(oracledb.Connection): pool = test_env.get_pool(connectiontype=MyConnection) with pool.acquire() as conn: assert isinstance(conn, MyConnection) + pool.close() def test_2436(test_env): @@ -821,6 +856,7 @@ class MyPool(oracledb.ConnectionPool): pool = test_env.get_pool(pool_class=MyPool) assert isinstance(pool, MyPool) + pool.close() def test_2437(test_env): @@ -838,6 +874,7 @@ def test_2438(skip_unless_pool_timed_wait_supported, test_env): ) with test_env.assert_raises_full_code("DPY-4005"): pool.acquire() + pool.close(force=True) def test_2439(skip_unless_call_timeout_supported, test_env): @@ -847,6 +884,7 @@ def test_2439(skip_unless_call_timeout_supported, test_env): assert conn.call_timeout == 0 with pool.acquire() as conn: assert conn.call_timeout == 0 + pool.close() def test_2440(test_env): @@ -862,12 +900,14 @@ def test_2441(test_env): ) num_conns = 10 active_sessions = set() - conns = [pool.acquire() for _ in range(num_conns)] - for conn in conns: - active_sessions.add(test_env.get_sid_serial(conn)) - assert pool.opened == num_conns - assert pool.busy == num_conns - assert len(active_sessions) == num_conns + with contextlib.ExitStack() as stack: + conns = [stack.enter_context(pool.acquire()) for _ in range(num_conns)] + for conn in conns: + active_sessions.add(test_env.get_sid_serial(conn)) + assert pool.opened == num_conns + assert pool.busy == num_conns + assert len(active_sessions) == num_conns + pool.close() def test_2442(skip_unless_thin_mode, test_env): @@ -944,8 +984,9 @@ def test_2448(test_env): "2448 - test create_pool() with edition" edition = test_env.edition_name pool = test_env.get_pool(edition=edition) - conn = pool.acquire() - assert conn.edition == edition + with pool.acquire() as conn: + assert conn.edition == edition + pool.close() def test_2449(test_env): @@ -1045,22 +1086,23 @@ def test_2456(test_env): def test_2457(skip_if_drcp, test_env): "2457 - ping pooled connection on receiving dead connection error" test_env.skip_unless_server_version(18) - admin_conn = test_env.get_admin_connection() - pool = test_env.get_pool(min=1, max=1, ping_interval=0) + with test_env.get_admin_connection() as admin_conn: + pool = test_env.get_pool(min=1, max=1, ping_interval=0) - # kill connection in pool - with admin_conn.cursor() as admin_cursor: - with pool.acquire() as conn: - sid, serial = test_env.get_sid_serial(conn) - sql = f"alter system kill session '{sid},{serial}'" - admin_cursor.execute(sql) + # kill connection in pool + with admin_conn.cursor() as admin_cursor: + with pool.acquire() as conn: + sid, serial = test_env.get_sid_serial(conn) + sql = f"alter system kill session '{sid},{serial}'" + admin_cursor.execute(sql) - # acquire connection which should succeed without failure - with pool.acquire() as conn: - with conn.cursor() as cursor: - cursor.execute("select user from dual") - (user,) = cursor.fetchone() - assert user == test_env.main_user.upper() + # acquire connection which should succeed without failure + with pool.acquire() as conn: + with conn.cursor() as cursor: + cursor.execute("select user from dual") + (user,) = cursor.fetchone() + assert user == test_env.main_user.upper() + pool.close() def test_2458(test_env): diff --git a/tests/test_2700_aq_dbobject.py b/tests/test_2700_aq_dbobject.py index 8a1f36b1..442cb6f6 100644 --- a/tests/test_2700_aq_dbobject.py +++ b/tests/test_2700_aq_dbobject.py @@ -182,17 +182,17 @@ def test_2708(conn, queue, book_data, test_env): props = conn.msgproperties(payload=book) queue.enqone(props) - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props is None - conn.commit() - props = queue.deqone() - other_conn.commit() - assert props is not None + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props is None + conn.commit() + props = queue.deqone() + other_conn.commit() + assert props is not None def test_2709(conn, queue, book_data, test_env): @@ -203,17 +203,17 @@ def test_2709(conn, queue, book_data, test_env): props = conn.msgproperties(payload=book) queue.enqone(props) - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - book = props.payload - results = (book.TITLE, book.AUTHORS, book.PRICE) - other_conn.commit() - assert results == book_data[0] + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + book = props.payload + results = (book.TITLE, book.AUTHORS, book.PRICE) + other_conn.commit() + assert results == book_data[0] def test_2710(conn, queue, book_data, test_env): @@ -225,19 +225,19 @@ def test_2710(conn, queue, book_data, test_env): props = conn.msgproperties(payload=book) queue.enqone(props) - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.deliverymode = oracledb.MSG_BUFFERED - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props.deliverymode == oracledb.MSG_BUFFERED - book = props.payload - results = (book.TITLE, book.AUTHORS, book.PRICE) - other_conn.commit() - assert results == book_data[0] + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.deliverymode = oracledb.MSG_BUFFERED + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props.deliverymode == oracledb.MSG_BUFFERED + book = props.payload + results = (book.TITLE, book.AUTHORS, book.PRICE) + other_conn.commit() + assert results == book_data[0] def test_2711(conn, queue, book_data, test_env): @@ -249,19 +249,19 @@ def test_2711(conn, queue, book_data, test_env): props = conn.msgproperties(payload=book) queue.enqone(props) - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props.deliverymode == oracledb.MSG_PERSISTENT - book = props.payload - results = (book.TITLE, book.AUTHORS, book.PRICE) - other_conn.commit() - assert results == book_data[0] + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props.deliverymode == oracledb.MSG_PERSISTENT + book = props.payload + results = (book.TITLE, book.AUTHORS, book.PRICE) + other_conn.commit() + assert results == book_data[0] def test_2712(conn, queue, book_data, test_env): @@ -273,19 +273,19 @@ def test_2712(conn, queue, book_data, test_env): props = conn.msgproperties(payload=book) queue.enqone(props) - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props.deliverymode == oracledb.MSG_PERSISTENT - book = props.payload - results = (book.TITLE, book.AUTHORS, book.PRICE) - other_conn.commit() - assert results == book_data[0] + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props.deliverymode == oracledb.MSG_PERSISTENT + book = props.payload + results = (book.TITLE, book.AUTHORS, book.PRICE) + other_conn.commit() + assert results == book_data[0] def test_2713(conn, queue, book_data, test_env): @@ -297,15 +297,15 @@ def test_2713(conn, queue, book_data, test_env): props = conn.msgproperties(payload=book) queue.enqone(props) - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props is None + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props is None def test_2714(skip_unless_thick_mode, conn, queue, book_data, test_env): @@ -317,17 +317,17 @@ def test_2714(skip_unless_thick_mode, conn, queue, book_data, test_env): queue.enqone(props) conn.commit() - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - transformation_str = f"{conn.username}.transform2" - queue.deqoptions.transformation = transformation_str - assert queue.deqoptions.transformation == transformation_str - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props.payload.PRICE == expected_price + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + transformation_str = f"{conn.username}.transform2" + queue.deqoptions.transformation = transformation_str + assert queue.deqoptions.transformation == transformation_str + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props.payload.PRICE == expected_price def test_2715(skip_unless_thick_mode, conn, queue, book_data, test_env): @@ -345,14 +345,14 @@ def test_2715(skip_unless_thick_mode, conn, queue, book_data, test_env): queue.enqone(props) conn.commit() - other_conn = test_env.get_connection() - books_type = other_conn.gettype(queue.payload_type.name) - queue = other_conn.queue(queue.name, books_type) - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props.payload.PRICE == expected_price + with test_env.get_connection() as other_conn: + books_type = other_conn.gettype(queue.payload_type.name) + queue = other_conn.queue(queue.name, books_type) + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props.payload.PRICE == expected_price def test_2716(conn, queue, test_env): @@ -440,6 +440,7 @@ def notification_callback(message=None, *args, **kwargs): with condition: assert condition.wait(5) other_conn.unsubscribe(sub) + other_conn.close() def test_2721(conn, cursor, queue): diff --git a/tests/test_2800_aq_bulk.py b/tests/test_2800_aq_bulk.py index c78faa28..e9576c0b 100644 --- a/tests/test_2800_aq_bulk.py +++ b/tests/test_2800_aq_bulk.py @@ -154,26 +154,26 @@ def test_2804(skip_unless_thick_mode, conn, queue, test_env): props1 = conn.msgproperties(payload="A first message") props2 = conn.msgproperties(payload="A second message") queue.enqmany([props1, props2]) - other_connection = test_env.get_connection() - other_queue = other_connection.queue(RAW_QUEUE_NAME) - other_queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - other_queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT - messages = other_queue.deqmany(5) - assert len(messages) == 0 - conn.commit() - messages = other_queue.deqmany(5) - assert len(messages) == 2 - other_connection.rollback() - - # second test with ENQ_IMMEDIATE (no commit required) - queue.enqoptions.visibility = oracledb.ENQ_IMMEDIATE - other_queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.enqmany([props1, props2]) - messages = other_queue.deqmany(5) - assert len(messages) == 4 - other_connection.rollback() - messages = other_queue.deqmany(5) - assert len(messages) == 0 + with test_env.get_connection() as other_connection: + other_queue = other_connection.queue(RAW_QUEUE_NAME) + other_queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + other_queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT + messages = other_queue.deqmany(5) + assert len(messages) == 0 + conn.commit() + messages = other_queue.deqmany(5) + assert len(messages) == 2 + other_connection.rollback() + + # second test with ENQ_IMMEDIATE (no commit required) + queue.enqoptions.visibility = oracledb.ENQ_IMMEDIATE + other_queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.enqmany([props1, props2]) + messages = other_queue.deqmany(5) + assert len(messages) == 4 + other_connection.rollback() + messages = other_queue.deqmany(5) + assert len(messages) == 0 def test_2805(conn, queue, test_env): diff --git a/tests/test_3000_subscription.py b/tests/test_3000_subscription.py index 34e383d6..3f7fec21 100644 --- a/tests/test_3000_subscription.py +++ b/tests/test_3000_subscription.py @@ -199,20 +199,20 @@ def test_3002(skip_unless_has_client_23, conn, test_env): # set up subscription data = AQSubscriptionData(1) - conn = test_env.get_connection(events=True) - conn.subscribe( - namespace=oracledb.SUBSCR_NAMESPACE_AQ, - name=queue.name, - timeout=10, - callback=data.callback_handler, - ) + with test_env.get_connection(events=True) as conn: + conn.subscribe( + namespace=oracledb.SUBSCR_NAMESPACE_AQ, + name=queue.name, + timeout=10, + callback=data.callback_handler, + ) - # enqueue a message - queue.enqone(conn.msgproperties(payload="Some data")) - conn.commit() + # enqueue a message + queue.enqone(conn.msgproperties(payload="Some data")) + conn.commit() - # wait for all messages to be sent - data.wait_for_messages() + # wait for all messages to be sent + data.wait_for_messages() @pytest.mark.skip("fails intermittently") @@ -251,19 +251,19 @@ def test_3004(skip_unless_has_client_23, test_env): def test_3005(skip_unless_has_client_23, test_env): "3005 - test registerquery with invalid parameters" data = DMLSubscriptionData(5) - conn = test_env.get_connection(events=True) - sub = conn.subscribe(callback=data.callback_handler) - pytest.raises( - TypeError, - sub.registerquery, - "select * from TestTempTable", - "invalid args", - ) - with test_env.assert_raises_full_code("ORA-00942"): - sub.registerquery("select * from Nonexistent") - with test_env.assert_raises_full_code("DPI-1013"): - sub.registerquery("insert into TestTempTable (IntCol) values (1)") - conn.unsubscribe(sub) + with test_env.get_connection(events=True) as conn: + sub = conn.subscribe(callback=data.callback_handler) + pytest.raises( + TypeError, + sub.registerquery, + "select * from TestTempTable", + "invalid args", + ) + with test_env.assert_raises_full_code("ORA-00942"): + sub.registerquery("select * from Nonexistent") + with test_env.assert_raises_full_code("DPI-1013"): + sub.registerquery("insert into TestTempTable (IntCol) values (1)") + conn.unsubscribe(sub) def test_3006(skip_unless_has_client_23, test_env): @@ -340,39 +340,39 @@ def callback_handler(message): def test_3008(skip_unless_has_client_23, test_env): "3008 - test unsubscribe with invalid parameter" - conn = test_env.get_connection(events=True) - pytest.raises(TypeError, conn.unsubscribe, "not a sub object") - sub = conn.subscribe(callback=lambda x: f"Message: {x}") - conn.unsubscribe(sub) - with test_env.assert_raises_full_code("DPI-1002"): + with test_env.get_connection(events=True) as conn: + pytest.raises(TypeError, conn.unsubscribe, "not a sub object") + sub = conn.subscribe(callback=lambda x: f"Message: {x}") conn.unsubscribe(sub) + with test_env.assert_raises_full_code("DPI-1002"): + conn.unsubscribe(sub) def test_3010(skip_unless_has_client_23, test_env): "3010 - test registerquery in the middle of an active transaction" - connection = test_env.get_connection(events=True) - cursor = connection.cursor() - cursor.execute("truncate table TestTempTable") - cursor.execute( - "insert into TestTempTable (IntCol, StringCol1) values (1, 'test')" - ) - sub = connection.subscribe(callback=lambda x: f"Msg: {x}") - with test_env.assert_raises_full_code("ORA-29975"): - sub.registerquery("select * from TestTempTable") - connection.unsubscribe(sub) + with test_env.get_connection(events=True) as connection: + cursor = connection.cursor() + cursor.execute("truncate table TestTempTable") + cursor.execute( + "insert into TestTempTable (IntCol, StringCol1) values (1, 'test')" + ) + sub = connection.subscribe(callback=lambda x: f"Msg: {x}") + with test_env.assert_raises_full_code("ORA-29975"): + sub.registerquery("select * from TestTempTable") + connection.unsubscribe(sub) def test_3011(skip_unless_has_client_23, test_env): "3011 - test registerquery with aq subscription" - connection = test_env.get_connection(events=True) - sub = connection.subscribe( - callback=lambda x: None, - namespace=oracledb.SUBSCR_NAMESPACE_AQ, - name="TEST_RAW_QUEUE", - ) - with test_env.assert_raises_full_code("ORA-24315"): - sub.registerquery("select * from TestTempTable") - connection.unsubscribe(sub) + with test_env.get_connection(events=True) as connection: + sub = connection.subscribe( + callback=lambda x: None, + namespace=oracledb.SUBSCR_NAMESPACE_AQ, + name="TEST_RAW_QUEUE", + ) + with test_env.assert_raises_full_code("ORA-24315"): + sub.registerquery("select * from TestTempTable") + connection.unsubscribe(sub) def test_3013(skip_unless_has_client_23, cursor, test_env): @@ -407,11 +407,11 @@ def callback(message): def test_3014(skip_unless_has_client_23, test_env): "3014 - test adding a consumer to a single consumer queue (negative)" - conn = test_env.get_connection(events=True) - single_consumer_queue = "TEST_RAW_QUEUE" - with test_env.assert_raises_full_code("ORA-25256"): - conn.subscribe( - callback=lambda x: None, - namespace=oracledb.SUBSCR_NAMESPACE_AQ, - name=f"{single_consumer_queue}:SUBSCRIBER", - ) + with test_env.get_connection(events=True) as conn: + single_consumer_queue = "TEST_RAW_QUEUE" + with test_env.assert_raises_full_code("ORA-25256"): + conn.subscribe( + callback=lambda x: None, + namespace=oracledb.SUBSCR_NAMESPACE_AQ, + name=f"{single_consumer_queue}:SUBSCRIBER", + ) diff --git a/tests/test_3800_typehandler.py b/tests/test_3800_typehandler.py index f783f33f..5333bbf1 100644 --- a/tests/test_3800_typehandler.py +++ b/tests/test_3800_typehandler.py @@ -153,31 +153,31 @@ def test_3804(cursor, test_env): building_one = Building(1, "The First Building", 5) building_two = Building(2, "The Second Building", 87) sql = "insert into TestTempTable (IntCol, StringCol1) values (:1, :2)" - conn = test_env.get_connection() - conn.inputtypehandler = input_type_handler - assert conn.inputtypehandler == input_type_handler - - cursor_one = conn.cursor() - cursor_two = conn.cursor() - cursor_one.execute(sql, [building_one.building_id, building_one]) - cursor_two.execute(sql, [building_two.building_id, building_two]) - conn.commit() - - expected_data = [ - (building_one.building_id, building_one), - (building_two.building_id, building_two), - ] - conn.outputtypehandler = output_type_handler - assert conn.outputtypehandler == output_type_handler - cursor_one.execute("select IntCol, StringCol1 from TestTempTable") - assert cursor_one.fetchvars[1].outconverter == Building.from_json - assert cursor_one.fetchall() == expected_data - - cursor_two.execute("select IntCol, StringCol1 from TestTempTable") - assert cursor_two.fetchall() == expected_data - other_cursor = cursor.connection.cursor() - with test_env.assert_raises_full_code("DPY-3002"): - other_cursor.execute(sql, (building_one.building_id, building_one)) + with test_env.get_connection() as conn: + conn.inputtypehandler = input_type_handler + assert conn.inputtypehandler == input_type_handler + + cursor_one = conn.cursor() + cursor_two = conn.cursor() + cursor_one.execute(sql, [building_one.building_id, building_one]) + cursor_two.execute(sql, [building_two.building_id, building_two]) + conn.commit() + + expected_data = [ + (building_one.building_id, building_one), + (building_two.building_id, building_two), + ] + conn.outputtypehandler = output_type_handler + assert conn.outputtypehandler == output_type_handler + cursor_one.execute("select IntCol, StringCol1 from TestTempTable") + assert cursor_one.fetchvars[1].outconverter == Building.from_json + assert cursor_one.fetchall() == expected_data + + cursor_two.execute("select IntCol, StringCol1 from TestTempTable") + assert cursor_two.fetchall() == expected_data + other_cursor = cursor.connection.cursor() + with test_env.assert_raises_full_code("DPY-3002"): + other_cursor.execute(sql, (building_one.building_id, building_one)) def test_3805(conn, cursor): diff --git a/tests/test_4300_cursor_other.py b/tests/test_4300_cursor_other.py index 33474f41..cc7cf401 100644 --- a/tests/test_4300_cursor_other.py +++ b/tests/test_4300_cursor_other.py @@ -685,31 +685,31 @@ def test_4346(cursor): def test_4347(skip_if_drcp, test_env): "4547 - kill connection with open cursor" - admin_conn = test_env.get_admin_connection() - conn = test_env.get_connection() - assert conn.is_healthy() - sid, serial = test_env.get_sid_serial(conn) - with admin_conn.cursor() as admin_cursor: - sql = f"alter system kill session '{sid},{serial}'" - admin_cursor.execute(sql) - with test_env.assert_raises_full_code("DPY-4011"): - with conn.cursor() as cursor: - cursor.execute("select user from dual") - assert not conn.is_healthy() + with test_env.get_admin_connection() as admin_conn: + conn = test_env.get_connection() + assert conn.is_healthy() + sid, serial = test_env.get_sid_serial(conn) + with admin_conn.cursor() as admin_cursor: + sql = f"alter system kill session '{sid},{serial}'" + admin_cursor.execute(sql) + with test_env.assert_raises_full_code("DPY-4011"): + with conn.cursor() as cursor: + cursor.execute("select user from dual") + assert not conn.is_healthy() def test_4348(skip_if_drcp, test_env): "4348 - kill connection in cursor context manager" - admin_conn = test_env.get_admin_connection() - conn = test_env.get_connection() - assert conn.is_healthy() - sid, serial = test_env.get_sid_serial(conn) - with admin_conn.cursor() as admin_cursor: - admin_cursor.execute(f"alter system kill session '{sid},{serial}'") - with test_env.assert_raises_full_code("DPY-4011"): - with conn.cursor() as cursor: - cursor.execute("select user from dual") - assert not conn.is_healthy() + with test_env.get_admin_connection() as admin_conn: + conn = test_env.get_connection() + assert conn.is_healthy() + sid, serial = test_env.get_sid_serial(conn) + with admin_conn.cursor() as admin_cursor: + admin_cursor.execute(f"alter system kill session '{sid},{serial}'") + with test_env.assert_raises_full_code("DPY-4011"): + with conn.cursor() as cursor: + cursor.execute("select user from dual") + assert not conn.is_healthy() def test_4349(conn, test_env): diff --git a/tests/test_5700_lob_var_async.py b/tests/test_5700_lob_var_async.py index 0e385f98..3da78c52 100644 --- a/tests/test_5700_lob_var_async.py +++ b/tests/test_5700_lob_var_async.py @@ -386,7 +386,9 @@ async def test_5714(async_conn, test_env): await _test_lob_operations(async_conn, test_env, "NCLOB") -async def test_5715(skip_if_implicit_pooling, async_conn, async_cursor): +async def test_5715( + skip_if_implicit_pooling, skip_unless_refcounting, async_conn, async_cursor +): "5715 - test temporary LOBs" await async_cursor.execute( "select sys_context('USERENV', 'SID') from dual" diff --git a/tests/test_6600_defaults.py b/tests/test_6600_defaults.py index f7c94cf2..578c788e 100644 --- a/tests/test_6600_defaults.py +++ b/tests/test_6600_defaults.py @@ -26,6 +26,7 @@ 6600 - Module for testing oracledb.defaults """ +import contextlib import decimal import os import tempfile @@ -62,9 +63,9 @@ def _verify_network_name_attr(test_env, name): def test_6600(test_env): "6600 - test setting defaults.arraysize" with test_env.defaults_context_manager("arraysize", 50): - conn = test_env.get_connection() - cursor = conn.cursor() - assert cursor.arraysize == oracledb.defaults.arraysize + with test_env.get_connection() as conn: + cursor = conn.cursor() + assert cursor.arraysize == oracledb.defaults.arraysize def test_6601(cursor, test_env): @@ -86,9 +87,9 @@ def test_6602(cursor, test_env): def test_6603(test_env): "6603 - test setting defaults.prefetchrows" with test_env.defaults_context_manager("prefetchrows", 20): - conn = test_env.get_connection() - cursor = conn.cursor() - assert cursor.prefetchrows == oracledb.defaults.prefetchrows + with test_env.get_connection() as conn: + cursor = conn.cursor() + assert cursor.prefetchrows == oracledb.defaults.prefetchrows def test_6604(test_env): @@ -97,22 +98,24 @@ def test_6604(test_env): with test_env.defaults_context_manager("stmtcachesize", 40): pool = test_env.get_pool() assert pool.stmtcachesize == oracledb.defaults.stmtcachesize - conn = pool.acquire() - assert conn.stmtcachesize == oracledb.defaults.stmtcachesize + with pool.acquire() as conn: + assert conn.stmtcachesize == oracledb.defaults.stmtcachesize + pool.close() pool = test_env.get_pool(stmtcachesize=new_stmtcachesize) assert pool.stmtcachesize == new_stmtcachesize - conn = pool.acquire() - assert conn.stmtcachesize == new_stmtcachesize + with pool.acquire() as conn: + assert conn.stmtcachesize == new_stmtcachesize + pool.close() def test_6605(test_env): "6605 - test setting defaults.stmtcachesize (standalone connection)" new_stmtcachesize = 25 with test_env.defaults_context_manager("stmtcachesize", 50): - conn = test_env.get_connection() - assert conn.stmtcachesize == oracledb.defaults.stmtcachesize - conn = test_env.get_connection(stmtcachesize=new_stmtcachesize) - assert conn.stmtcachesize == new_stmtcachesize + with test_env.get_connection() as conn: + assert conn.stmtcachesize == oracledb.defaults.stmtcachesize + with test_env.get_connection(stmtcachesize=new_stmtcachesize) as conn: + assert conn.stmtcachesize == new_stmtcachesize def test_6606(cursor, test_env): @@ -154,22 +157,28 @@ def test_6609(test_env): new_value = 29 with test_env.defaults_context_manager("stmtcachesize", value): pool = test_env.get_pool() - pooled_conn = pool.acquire() params = oracledb.ConnectParams() - standalone_conn = test_env.get_connection() - with test_env.defaults_context_manager("stmtcachesize", new_value): - assert pool.stmtcachesize == value - assert pooled_conn.stmtcachesize == value - assert params.stmtcachesize == value - assert standalone_conn.stmtcachesize == value - pool = test_env.get_pool() - pooled_conn = pool.acquire() - params = oracledb.ConnectParams() - standalone_conn = test_env.get_connection() - assert pool.stmtcachesize == new_value - assert pooled_conn.stmtcachesize == new_value - assert params.stmtcachesize == new_value - assert standalone_conn.stmtcachesize == new_value + with contextlib.ExitStack() as stack: + pooled_conn = stack.enter_context(pool.acquire()) + standalone_conn = stack.enter_context(test_env.get_connection()) + with test_env.defaults_context_manager("stmtcachesize", new_value): + assert pool.stmtcachesize == value + assert pooled_conn.stmtcachesize == value + assert params.stmtcachesize == value + assert standalone_conn.stmtcachesize == value + pool.release(pooled_conn) + pool.close() + pool = test_env.get_pool() + params = oracledb.ConnectParams() + pooled_conn = stack.enter_context(pool.acquire()) + standalone_conn = stack.enter_context( + test_env.get_connection() + ) + assert pool.stmtcachesize == new_value + assert pooled_conn.stmtcachesize == new_value + assert params.stmtcachesize == new_value + assert standalone_conn.stmtcachesize == new_value + pool.close() def test_6610(test_env): diff --git a/tests/test_7300_unsupported_features_thin.py b/tests/test_7300_unsupported_features_thin.py index 439bf70f..9125f09a 100644 --- a/tests/test_7300_unsupported_features_thin.py +++ b/tests/test_7300_unsupported_features_thin.py @@ -46,6 +46,7 @@ def test_7300(test_env): pool.max_sessions_per_shard with test_env.assert_raises_full_code("DPY-3001"): pool.max_sessions_per_shard = 2 + pool.close() def test_7302(test_env): @@ -70,3 +71,4 @@ def test_7304(test_env): pool = test_env.get_pool() with test_env.assert_raises_full_code("DPY-3001"): pool.acquire(tag="unimportant") + pool.close() diff --git a/tests/test_7800_aq_raw.py b/tests/test_7800_aq_raw.py index dded8fe4..8b5bc0f6 100644 --- a/tests/test_7800_aq_raw.py +++ b/tests/test_7800_aq_raw.py @@ -159,15 +159,15 @@ def test_7807(queue, conn, test_env): props = conn.msgproperties(payload=value) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue("TEST_RAW_QUEUE") - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props is None - conn.commit() - props = queue.deqone() - assert props is not None + with test_env.get_connection() as other_conn: + queue = other_conn.queue("TEST_RAW_QUEUE") + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props is None + conn.commit() + props = queue.deqone() + assert props is not None def test_7808(queue, conn, test_env): @@ -177,16 +177,16 @@ def test_7808(queue, conn, test_env): props = conn.msgproperties(payload=value) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue("TEST_RAW_QUEUE") - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - value = props.payload - results = value - other_conn.commit() - assert results == RAW_DATA[0] + with test_env.get_connection() as other_conn: + queue = other_conn.queue("TEST_RAW_QUEUE") + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + value = props.payload + results = value + other_conn.commit() + assert results == RAW_DATA[0] def test_7809(queue, conn, test_env): @@ -197,18 +197,18 @@ def test_7809(queue, conn, test_env): props = conn.msgproperties(payload=value) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue("TEST_RAW_QUEUE") - queue.deqoptions.deliverymode = oracledb.MSG_BUFFERED - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - value = props.payload - results = value - other_conn.commit() - assert results == RAW_DATA[0] - assert props.deliverymode == oracledb.MSG_BUFFERED + with test_env.get_connection() as other_conn: + queue = other_conn.queue("TEST_RAW_QUEUE") + queue.deqoptions.deliverymode = oracledb.MSG_BUFFERED + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + value = props.payload + results = value + other_conn.commit() + assert results == RAW_DATA[0] + assert props.deliverymode == oracledb.MSG_BUFFERED def test_7810(queue, conn, test_env): @@ -219,18 +219,18 @@ def test_7810(queue, conn, test_env): props = conn.msgproperties(payload=value) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue("TEST_RAW_QUEUE") - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - value = props.payload - results = value - other_conn.commit() - assert results == RAW_DATA[0] - assert props.deliverymode == oracledb.MSG_PERSISTENT + with test_env.get_connection() as other_conn: + queue = other_conn.queue("TEST_RAW_QUEUE") + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + value = props.payload + results = value + other_conn.commit() + assert results == RAW_DATA[0] + assert props.deliverymode == oracledb.MSG_PERSISTENT def test_7811(queue, conn, test_env): @@ -241,17 +241,17 @@ def test_7811(queue, conn, test_env): props = conn.msgproperties(payload=value) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue("TEST_RAW_QUEUE") - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - value = props.payload - results = value - other_conn.commit() - assert results == RAW_DATA[0] + with test_env.get_connection() as other_conn: + queue = other_conn.queue("TEST_RAW_QUEUE") + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + value = props.payload + results = value + other_conn.commit() + assert results == RAW_DATA[0] def test_7812(queue, conn, test_env): @@ -262,14 +262,14 @@ def test_7812(queue, conn, test_env): props = conn.msgproperties(payload=value) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue("TEST_RAW_QUEUE") - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props is None + with test_env.get_connection() as other_conn: + queue = other_conn.queue("TEST_RAW_QUEUE") + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props is None def test_7813(queue, conn, test_env): diff --git a/tests/test_8300_aq_json.py b/tests/test_8300_aq_json.py index a66ec107..7a70d7c3 100644 --- a/tests/test_8300_aq_json.py +++ b/tests/test_8300_aq_json.py @@ -210,15 +210,15 @@ def test_8307(queue, conn, test_env): props = conn.msgproperties(payload=data) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue(JSON_QUEUE_NAME, "JSON") - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - assert props is None - conn.commit() - props = queue.deqone() - assert props is not None + with test_env.get_connection() as other_conn: + queue = other_conn.queue(JSON_QUEUE_NAME, "JSON") + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + assert props is None + conn.commit() + props = queue.deqone() + assert props is not None def test_8308(queue, conn, test_env): @@ -228,16 +228,16 @@ def test_8308(queue, conn, test_env): props = conn.msgproperties(payload=data) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue(JSON_QUEUE_NAME, "JSON") - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - data = props.payload - results = data - other_conn.commit() - assert results == JSON_DATA[0] + with test_env.get_connection() as other_conn: + queue = other_conn.queue(JSON_QUEUE_NAME, "JSON") + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_ON_COMMIT + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + data = props.payload + results = data + other_conn.commit() + assert results == JSON_DATA[0] def test_8309(queue, conn, test_env): @@ -248,17 +248,17 @@ def test_8309(queue, conn, test_env): props = conn.msgproperties(payload=data) queue.enqone(props) - other_conn = test_env.get_connection() - queue = other_conn.queue(JSON_QUEUE_NAME, "JSON") - queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT - queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG - queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE - queue.deqoptions.wait = oracledb.DEQ_NO_WAIT - props = queue.deqone() - data = props.payload - results = data - other_conn.commit() - assert results == JSON_DATA[0] + with test_env.get_connection() as other_conn: + queue = other_conn.queue(JSON_QUEUE_NAME, "JSON") + queue.deqoptions.deliverymode = oracledb.MSG_PERSISTENT + queue.deqoptions.navigation = oracledb.DEQ_FIRST_MSG + queue.deqoptions.visibility = oracledb.DEQ_IMMEDIATE + queue.deqoptions.wait = oracledb.DEQ_NO_WAIT + props = queue.deqone() + data = props.payload + results = data + other_conn.commit() + assert results == JSON_DATA[0] def test_8310(queue, conn, test_env): From 6e0d8b9da4b259e1b11ad648d354ca659f537a6a Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:44:51 -0700 Subject: [PATCH 26/32] Eliminated race condition in background thread/coroutine management for connection pools. --- doc/src/release_notes.rst | 2 ++ src/oracledb/impl/thin/pool.pyx | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 51e9bce5..eca22bb0 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -40,6 +40,8 @@ Common Changes (`issue 554 `__). #) Fixed regression with contents of :data:`Cursor.description` when calling :meth:`Cursor.parse()` with a query that returns LOBs. +#) Eliminated race condition in background thread/coroutine management for + connection pools. #) Adjusted code and tests to be capable of being run in environments other than CPython. diff --git a/src/oracledb/impl/thin/pool.pyx b/src/oracledb/impl/thin/pool.pyx index c274dbc7..1c739b68 100644 --- a/src/oracledb/impl/thin/pool.pyx +++ b/src/oracledb/impl/thin/pool.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2020, 2025, Oracle and/or its affiliates. +# Copyright (c) 2020, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -48,7 +48,7 @@ cdef class BaseThinPoolImpl(BasePoolImpl): uint32_t _ping_timeout object _wait_timeout object _bg_task - object _bg_task_condition + object _bg_task_event object _condition object _timeout_task object _ssl_session @@ -489,7 +489,7 @@ cdef class ThinPoolImpl(BaseThinPoolImpl): def __init__(self, str dsn, PoolParamsImpl params): super().__init__(dsn, params) self._condition = threading.Condition() - self._bg_task_condition = threading.Condition() + self._bg_task_event = threading.Event() self._bg_task = threading.Thread(target=self._bg_task_func) self._bg_task.start() @@ -547,8 +547,8 @@ cdef class ThinPoolImpl(BaseThinPoolImpl): continue # otherwise, nothing to do yet, wait for notifications! - with self._bg_task_condition: - self._bg_task_condition.wait() + self._bg_task_event.wait() + self._bg_task_event.clear() # stop the timeout task, if one is active if self._timeout_task is not None: @@ -573,8 +573,7 @@ cdef class ThinPoolImpl(BaseThinPoolImpl): """ Notify the background task that work needs to be done. """ - with self._bg_task_condition: - self._bg_task_condition.notify() + self._bg_task_event.set() cdef int _process_request(self, PooledConnRequest request) except -1: """ @@ -669,7 +668,7 @@ cdef class AsyncThinPoolImpl(BaseThinPoolImpl): def __init__(self, str dsn, PoolParamsImpl params): super().__init__(dsn, params) self._condition = asyncio.Condition() - self._bg_task_condition = asyncio.Condition() + self._bg_task_event = asyncio.Event() self._bg_task = asyncio.create_task(self._bg_task_func()) async def _acquire_helper(self, PooledConnRequest request): @@ -741,8 +740,8 @@ cdef class AsyncThinPoolImpl(BaseThinPoolImpl): continue # otherwise, nothing to do yet, wait for notifications! - async with self._bg_task_condition: - await self._bg_task_condition.wait() + await self._bg_task_event.wait() + self._bg_task_event.clear() # stop the timeout task, if one is active if self._timeout_task is not None: @@ -766,8 +765,7 @@ cdef class AsyncThinPoolImpl(BaseThinPoolImpl): """ if self._bg_notify_task is None or self._bg_notify_task.done(): async def helper(): - async with self._bg_task_condition: - self._bg_task_condition.notify() + self._bg_task_event.set() self._bg_notify_task = asyncio.create_task(helper()) async def _process_request(self, PooledConnRequest request): From f8be001d9862d6b0b6ec6158b67affef7a70556e Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:45:15 -0700 Subject: [PATCH 27/32] Fixed bug causing hang when using asyncio and the database closes the connection before the connection is returned to the user. --- doc/src/release_notes.rst | 3 +++ src/oracledb/impl/thin/protocol.pyx | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index eca22bb0..942ea66c 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -40,6 +40,9 @@ Common Changes (`issue 554 `__). #) Fixed regression with contents of :data:`Cursor.description` when calling :meth:`Cursor.parse()` with a query that returns LOBs. +#) Fixed bug causing hang when using :ref:`asyncio ` + and the database closes the connection before the connection is returned to + the user. #) Eliminated race condition in background thread/coroutine management for connection pools. #) Adjusted code and tests to be capable of being run in environments other diff --git a/src/oracledb/impl/thin/protocol.pyx b/src/oracledb/impl/thin/protocol.pyx index c34bcff6..db917c5b 100644 --- a/src/oracledb/impl/thin/protocol.pyx +++ b/src/oracledb/impl/thin/protocol.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2020, 2025, Oracle and/or its affiliates. +# Copyright (c) 2020, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -976,10 +976,10 @@ cdef class BaseAsyncProtocol(BaseProtocol): self._read_buf._transport = None self._write_buf._transport = None self._read_buf._pending_error_num = TNS_ERR_SESSION_SHUTDOWN - if self._read_buf._waiter is not None \ - and not self._read_buf._waiter.done(): - error = errors._create_err(errors.ERR_CONNECTION_CLOSED) - self._read_buf._waiter.set_exception(error.exc_type(error)) + if self._read_buf._waiter is not None \ + and not self._read_buf._waiter.done(): + error = errors._create_err(errors.ERR_CONNECTION_CLOSED) + self._read_buf._waiter.set_exception(error.exc_type(error)) def data_received(self, data): """ From 6072f01b420af4c2d36c1b9f7b1421aab64ea336 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:45:33 -0700 Subject: [PATCH 28/32] Grammar fix. --- doc/src/user_guide/globalization.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/user_guide/globalization.rst b/doc/src/user_guide/globalization.rst index e0922476..68b45676 100644 --- a/doc/src/user_guide/globalization.rst +++ b/doc/src/user_guide/globalization.rst @@ -106,7 +106,7 @@ The larger file ``timezlrg_.dat`` contains all time zone information. This is the file used by default. The smaller ``timezone_.dat`` file contains only the most commonly used time zones. -The filenames shows the version of the time zone files, in this example it is +The filenames show the version of the time zone files. In this example it is version 43. The Oracle Database documentation contains more information about time zone From 36a29517530bfe311dab41218a3bc3d80700fe2c Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:47:04 -0700 Subject: [PATCH 29/32] Fixed bug when decoding PL/SQL booleans in Oracle Database 12.1 (#565). --- doc/src/release_notes.rst | 2 ++ src/oracledb/impl/base/buffer.pyx | 12 +++++++++++- src/oracledb/impl/base/decoders.pyx | 10 +--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 942ea66c..bd0229c2 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -19,6 +19,8 @@ oracledb `3.4.2 `__). #) Fixed bug when a :ref:`DbObject ` instance contains an attribute of type ``SYS.XMLTYPE``. diff --git a/src/oracledb/impl/base/buffer.pyx b/src/oracledb/impl/base/buffer.pyx index dd72f900..6adafffc 100644 --- a/src/oracledb/impl/base/buffer.pyx +++ b/src/oracledb/impl/base/buffer.pyx @@ -183,7 +183,17 @@ cdef class Buffer: elif ora_type_num == ORA_TYPE_NUM_BINARY_FLOAT: decode_binary_float(ptr, num_bytes, &data.buffer) elif ora_type_num == ORA_TYPE_NUM_BOOLEAN: - decode_bool(ptr, num_bytes, &data.buffer) + # inside a database object, the boolean is represented as a + # big endian 32-bit integer (either 0 or 1) + if from_dbobject: + data.buffer.as_bool = ptr[num_bytes - 1] == 1 + # outside a database object, the boolean is represented as an + # encoded integer (0x00 for false and 0x0101 for true); older + # versions like 12.1 also return 0x8101 (-1) for null values + # but this can safely be ignored as the null indicator is sent + # as a separate field afterwards anyways + else: + data.buffer.as_bool = ptr[0] == 1 elif ora_type_num in ( ORA_TYPE_NUM_CHAR, ORA_TYPE_NUM_LONG, diff --git a/src/oracledb/impl/base/decoders.pyx b/src/oracledb/impl/base/decoders.pyx index 11f3894d..3519373c 100644 --- a/src/oracledb/impl/base/decoders.pyx +++ b/src/oracledb/impl/base/decoders.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2024, Oracle and/or its affiliates. +# Copyright (c) 2024, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -84,14 +84,6 @@ cdef int decode_binary_float(const uint8_t *ptr, ssize_t num_bytes, memcpy(&buffer.as_float, &all_bits, 4) -cdef int decode_bool(const uint8_t* ptr, ssize_t num_bytes, - OracleDataBuffer *buffer) except -1: - """ - Decode a boolean value from raw bytes. - """ - buffer.as_bool = (ptr[num_bytes - 1] == 1) - - cdef int decode_date(const uint8_t* ptr, ssize_t num_bytes, OracleDataBuffer *buffer) except -1: """ From 4a94025de99763fd0d16d1c2d79d416b9a075e12 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:47:30 -0700 Subject: [PATCH 30/32] Eliminated memory leak when converting a third party data frame to one used internally by the driver (#561). --- doc/src/release_notes.rst | 3 +++ src/oracledb/impl/arrow/dataframe.pyx | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index bd0229c2..9a42b400 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -42,6 +42,9 @@ Common Changes (`issue 554 `__). #) Fixed regression with contents of :data:`Cursor.description` when calling :meth:`Cursor.parse()` with a query that returns LOBs. +#) Eliminated memory leak when converting a third party data frame to one used + internally by the driver + (`issue 561 `__). #) Fixed bug causing hang when using :ref:`asyncio ` and the database closes the connection before the connection is returned to the user. diff --git a/src/oracledb/impl/arrow/dataframe.pyx b/src/oracledb/impl/arrow/dataframe.pyx index 837b621d..5b88662e 100644 --- a/src/oracledb/impl/arrow/dataframe.pyx +++ b/src/oracledb/impl/arrow/dataframe.pyx @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2025, Oracle and/or its affiliates. +# Copyright (c) 2025, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -71,6 +71,7 @@ cdef class DataFrameImpl: array_impl.populate_from_array(df_impl.schema_impls[i], arrow_array.children[i]) df_impl.arrays.append(array_impl) + ArrowArrayRelease(&arrow_array) ArrowArrayStreamRelease(arrow_stream) return df_impl From 81ceb554a0bfb52eb64b7b3870907d9b19bf15bd Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 23 Jan 2026 09:48:01 -0700 Subject: [PATCH 31/32] Fixed bug which caused Connection.call_timeout to be reset to zero when a ping is internally executed by the pool before the connection is returned to the user (#558). --- doc/src/release_notes.rst | 4 ++++ src/oracledb/impl/thin/pool.pyx | 14 ++++++++++---- tests/test_2400_pool.py | 17 ++++++++++++++++- tests/test_5500_pool_async.py | 17 ++++++++++++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 9a42b400..ddc097f3 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -19,6 +19,10 @@ oracledb `3.4.2 `__). #) Fixed bug when decoding PL/SQL booleans in Oracle Database 12.1 (`issue 565 `__). #) Fixed bug when a :ref:`DbObject ` instance contains an attribute diff --git a/src/oracledb/impl/thin/pool.pyx b/src/oracledb/impl/thin/pool.pyx index 1c739b68..cb3f2601 100644 --- a/src/oracledb/impl/thin/pool.pyx +++ b/src/oracledb/impl/thin/pool.pyx @@ -579,13 +579,16 @@ cdef class ThinPoolImpl(BaseThinPoolImpl): """ Processes a request. """ - cdef BaseThinConnImpl conn_impl + cdef: + BaseThinConnImpl conn_impl + uint32_t orig_call_timeout try: if request.requires_ping: try: + orig_call_timeout = request.conn_impl._call_timeout request.conn_impl.set_call_timeout(self._ping_timeout) request.conn_impl.ping() - request.conn_impl.set_call_timeout(0) + request.conn_impl.set_call_timeout(orig_call_timeout) except exceptions.Error: request.conn_impl._protocol._disconnect() request.conn_impl = None @@ -772,13 +775,16 @@ cdef class AsyncThinPoolImpl(BaseThinPoolImpl): """ Processes a request. """ - cdef BaseThinConnImpl conn_impl + cdef: + BaseThinConnImpl conn_impl + uint32_t orig_call_timeout try: if request.requires_ping: try: + orig_call_timeout = request.conn_impl._call_timeout request.conn_impl.set_call_timeout(self._ping_timeout) await request.conn_impl.ping() - request.conn_impl.set_call_timeout(0) + request.conn_impl.set_call_timeout(orig_call_timeout) except exceptions.Error: request.conn_impl._protocol._disconnect() request.conn_impl = None diff --git a/tests/test_2400_pool.py b/tests/test_2400_pool.py index 0b2577ef..07746efb 100644 --- a/tests/test_2400_pool.py +++ b/tests/test_2400_pool.py @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2020, 2025, Oracle and/or its affiliates. +# Copyright (c) 2020, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -1110,3 +1110,18 @@ def test_2458(test_env): with test_env.assert_raises_full_code("ORA-01017"): pool = test_env.get_pool(password=test_env.main_password + "X") pool.acquire() + + +def test_2459(test_env): + "2459 - verify call_timeout is unchanged after internal ping performed" + desired_value = 5000 + + def callback(conn, tag): + conn.call_timeout = desired_value + + pool = test_env.get_pool(session_callback=callback, ping_interval=0) + with pool.acquire() as conn: + assert conn.call_timeout == desired_value + with pool.acquire() as conn: + assert conn.call_timeout == desired_value + pool.close() diff --git a/tests/test_5500_pool_async.py b/tests/test_5500_pool_async.py index bc8b2a93..970d387e 100644 --- a/tests/test_5500_pool_async.py +++ b/tests/test_5500_pool_async.py @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2023, 2025, Oracle and/or its affiliates. +# Copyright (c) 2023, 2026, Oracle and/or its affiliates. # # This software is dual-licensed to you under the Universal Permissive License # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License @@ -684,3 +684,18 @@ async def test_5544(test_env): pool = test_env.get_pool_async(password=test_env.main_password + "X") with test_env.assert_raises_full_code("ORA-01017"): await pool.acquire() + + +async def test_5545(test_env): + "5545 - verify call_timeout is unchanged after internal ping performed" + desired_value = 5000 + + async def callback(conn, tag): + conn.call_timeout = desired_value + + pool = test_env.get_pool_async(session_callback=callback, ping_interval=0) + async with pool.acquire() as conn: + assert conn.call_timeout == desired_value + async with pool.acquire() as conn: + assert conn.call_timeout == desired_value + await pool.close() From 51581eeb0a626fb3df4e25e00ddb3a28137d3831 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Wed, 28 Jan 2026 09:47:30 -0700 Subject: [PATCH 32/32] Preparing to release python-oracledb 3.4.2. --- doc/src/release_notes.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index ddc097f3..b0e8ed22 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -13,8 +13,8 @@ Release changes are listed as affecting Thin Mode (the default runtime behavior of python-oracledb), as affecting the optional :ref:`Thick Mode `, or as being 'Common' for changes that impact both modes. -oracledb `3.4.2 `__ (TBD) --------------------------------------------------------------------------------------------- +oracledb `3.4.2 `__ (January 2026) +----------------------------------------------------------------------------------------------------- Thin Mode Changes +++++++++++++++++ @@ -28,9 +28,6 @@ Thin Mode Changes #) Fixed bug when a :ref:`DbObject ` instance contains an attribute of type ``SYS.XMLTYPE``. -Thick Mode Changes -++++++++++++++++++ - Common Changes ++++++++++++++