oracle / oracle/python-oracledb

thick mode connect isn't honoring TNS_ADMIN or using ldap connection

Open
#398 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
451
Forks
119
PR merge metrics
No merged PRs in 30d

Description

  1. What versions are you using?

platform.platform: macOS-15.0-arm64-arm-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.12.6
oracledb.version: 2.4.1

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

Error

  1. What error(s) or behavior you are seeing?

When trying to connect to a database I'm getting the following error:

$ env | grep -E 'ORA|TNS|PATH'
TNS_ADMIN=/opt/oracle
PATH=/opt/oracle/instantclient_23_3:...
INFOPATH=/opt/homebrew/share/info:
ORACLE_HOME=/opt/oracle/instantclient_23_3

$ python test.py
Traceback (most recent call last):
File "/Users/slords/test.py", line 8, in
c=oracledb.connect(user=user, password=password, dsn=dsn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/slords/.venv/lib/python3.12/site-packages/oracledb/connection.py", line 1169, in connect
return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/slords/.venv/lib/python3.12/site-packages/oracledb/connection.py", line 554, in init
impl.connect(params_impl, pool_impl)
File "src/oracledb/impl/thick/connection.pyx", line 494, in oracledb.thick_impl.ThickConnImpl.connect
File "src/oracledb/impl/thick/utils.pyx", line 446, in oracledb.thick_impl._raise_from_info
oracledb.exceptions.DatabaseError: ORA-12154: Cannot connect to database. Could not find alias whse_dev in /opt/oracle/instantclient_23_3/network/admin/tnsnames.ora.
Help: https://docs.oracle.com/error-help/db/ora-12154/

If I run the same connect using sqlplus it connects fine to the database. I've got sqlnet.ora and ldap.ora in /opt/oracle. We don't use tnsnames.ora and that file has never existed in any of our installs.

  1. Does your application call init_oracle_client()?

Yes

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

$ cat test.py
import oracledb
oracledb.init_oracle_client(lib_dir='/opt/oracle/instantclient_23_3')

user='user'
password='pass'
dsn='ldap_alias'

c=oracledb.connect(user=user, password=password, dsn=dsn)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the runnable test.py and the init_oracle_client() call, then compare how the connection uses TNS_ADMIN, sqlnet.ora, and ldap.ora with the working sqlplus setup. Reproduce the ORA-12154 error and trace the Thick-mode connection path; done means ldap_alias connects using the LDAP configuration in /opt/oracle without requiring tnsnames.ora.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.