oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
339 stars 67 forks source link

Bequeath connections are failing with ORA-12545 #114

Closed theo-fokkinga closed 1 year ago

theo-fokkinga commented 1 year ago
  1. What versions are you using?

Database version: Oracle 19.17.0.0.0

platform.platform: Linux-5.4.17-2136.313.6.el7uek.x86_64-x86_64-with-glibc2.17 sys.maxsize > 2**32: True platform.python_version: 3.9.16

oracledb.version: 1.2.1

  1. Is it an error or a hang or a crash? Error

  2. What error(s) or behavior you are seeing? When calling the connect function for a bequeath connection, like:

    connection = oracledb.connect(mode=oracledb.AUTH_MODE_SYSDBA)

    The following error occurs:

Traceback (most recent call last):
  File "example_failing_bequeath_connection.py", line 11, in <module>
    connection = oracledb.connect(mode=sysdba_mode)
  File "/home/john/python3_oracledb_121/lib/python3.9/site-packages/oracledb/connection.py", line 1013, in connect
    return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
  File "/home/john/python3_oracledb_121/lib/python3.9/site-packages/oracledb/connection.py", line 138, in __init__
    impl.connect(params_impl, pool_impl)
  File "src/oracledb/impl/thick/connection.pyx", line 387, in oracledb.thick_impl.ThickConnImpl.connect
  File "src/oracledb/impl/thick/utils.pyx", line 410, in oracledb.thick_impl._raise_from_odpi
  File "src/oracledb/impl/thick/utils.pyx", line 400, in oracledb.thick_impl._raise_from_info
oracledb.exceptions.DatabaseError: ORA-12545: Connect failed because target host or object does not exist
  1. Does your application call init_oracle_client()? Yes, running in thick mode.

  2. Include a runnable Python script that shows the problem.

    
    import os
    import oracledb

os.environ["ORACLE_HOME"] = "/u01/app/oracle/product/19.0.0.0/db_1" os.environ["ORACLE_SID"] = "ORCL" oracledb.init_oracle_client() connection = oracledb.connect(mode=oracledb.AUTH_MODE_SYSDBA)

connection.close()


When running in debug mode I found that the connection is being made using the connect_string:

'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=None)(PORT=1521)))(CONNECT_DATA=)(SECURITY=(SSL_SERVER_DN_MATCH=ON)))'

This explains the ORA-12545 error message. 

It looks like a regression bug in `src/oracledb/impl/base/connect_params.pyx`, in the `get_connect_string` function (commit 847004a2caa3bce345c46101c02633153321d43e) introduced in version 1.2.0.  
In version 1.0.1 a fix was included to 'restore support for bequeath connection` (commit 5852bae2c2595d401405327244a60b2a8e4e9a6d), but the change in 1.2.0 altered the same line. In version 1.1.1 the error does not occur. 

Just for testing purposes, I changed the code as follows and then bequeath connections are working fine:

--- a/src/oracledb/impl/base/connect_params.pyx +++ b/src/oracledb/impl/base/connect_params.pyx @@ -538,7 +538,7 @@ cdef class ConnectParamsImpl: will be a connect string built up from the components supplied when the object was built. """

anthony-tuininga commented 1 year ago

Thanks for the report. I'll get that corrected!

anthony-tuininga commented 1 year ago

I have pushed a patch that should correct this issue and added a relevant test case. If you are able to build from source you can verify that it corrects your issue as well.

theo-fokkinga commented 1 year ago

I can confirm that the issue is fixed with this patch included. Thanks!

anthony-tuininga commented 1 year ago

This patch is included in version 1.2.2 which was just released.