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

Home Page:https://oracle.github.io/python-oracledb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oracledb.connect() exits silently using instantclient-basic-macos.arm64 with older Python (Oracle Bug 36790189)

matepalocska opened this issue · comments

  1. What versions are you using?
    cffi==1.16.0
    cryptography==42.0.8
    oracledb==2.2.1
    pycparser==2.22

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.22.0.0.0

platform.platform: macOS-14.5-arm64-arm-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.10.7
oracledb.version: 2.2.1

  1. Is it an error or a hang or a crash?
    It's a "silent" crash. The python debugger flashes the Server[pid-2005] disconnected unexpectedly message, then disappears immediately. No other error message is shown.

  2. What error(s) or behavior you are seeing?
    The execution unexpectedly exits when trying to connect to the database, with the correct credentials. I also have DPI_DEBUG_LEVEL set to 64. TNS_ADMIN and ORACLE_HOME environment variables are set accordingly. SQLPlus is installed, no issue there - the Instant Client should be OK.
    Note: When running the same code, but in a Rosetta emulated terminal (using the instantclient_19_8_x86_64, and the intel package of the same modules), the connection works as expected.

  3. Does your application call init_oracle_client()?

Yes, calling init_oracle_client() - using thick mode (see point 7).

  1. Include a runnable Python script that shows the problem.
import sys
import platform
import oracledb

# Printing versions
print("platform.platform:", platform.platform())
print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
print("platform.python_version:", platform.python_version())
print("oracledb.__version__:", oracledb.__version__)

# Initialize the Oracle client library
if platform.machine() == 'arm64':
	print("current machine is ARM64")
	oracledb.init_oracle_client(lib_dir='/Users/matepalocska/instantclient_23_3_arm64')
elif platform.machine() == 'x86_64':
	print("current machine is x86_64")
	oracledb.init_oracle_client(lib_dir='/Users/matepalocska/instantclient_19_8_x86_64')
else:
	raise Exception("Unsupported platform")


# Specify your Oracle database credentials and DSN
username = "username"
password = "password"
dsn = "service_name"

# Connect to the Oracle database
try:
	with oracledb.connect(user=username, password=password, dsn=dsn) as connection:
		with connection.cursor() as cursor:
			sql = "SELECT sysdate FROM dual"
			cursor.execute(sql)
			for row in cursor:
				print(row)
except oracledb.DatabaseError as e:
	print("Database error:", e)
except Exception as e:
	print("Exception occurred:", e)

Output when using ARM package

platform.platform: macOS-14.5-arm64-arm-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.10.7
oracledb.version: 2.2.1
current machine is ARM64
ODPI [216673] 2024-06-26 16:26:30.299: ODPI-C 5.2.0
ODPI [216673] 2024-06-26 16:26:30.299: debugging messages initialized at level 64
ODPI [216673] 2024-06-26 16:26:30.299: Context Parameters:
ODPI [216673] 2024-06-26 16:26:30.299: Oracle Client Lib Dir: /Users/matepalocska/instantclient_23_3_arm64
ODPI [216673] 2024-06-26 16:26:30.299: Oracle Client Config Dir: > /Users/matepalocska/instantclient_23_3_arm64/network/admin
ODPI [216673] 2024-06-26 16:26:30.299: Environment Variables:
ODPI [216673] 2024-06-26 16:26:30.299: ORACLE_HOME => "/Users/matepalocska/instantclient_23_3_arm64"
ODPI [216673] 2024-06-26 16:26:30.299: TNS_ADMIN => "/Users/matepalocska/instantclient_23_3_arm64/network/admin"
ODPI [216673] 2024-06-26 16:26:30.299: load in parameter directory
ODPI [216673] 2024-06-26 16:26:30.299: load in dir /Users/matepalocska/instantclient_23_3_arm64
ODPI [216673] 2024-06-26 16:26:30.299: load with name /Users/matepalocska/instantclient_23_3_arm64/libclntsh.dylib
ODPI [216673] 2024-06-26 16:26:30.608: load by OS successful
ODPI [216673] 2024-06-26 16:26:30.608: validating loaded library

  • Connect doesn't happen, exits immediately.

Output when using intel package in emulated environment:

platform.platform: macOS-14.5-x86_64-i386-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.10.7
oracledb.version: 2.2.1
current machine is x86_64
ODPI [227043] 2024-06-26 16:32:41.529: ODPI-C 5.2.0
ODPI [227043] 2024-06-26 16:32:41.529: debugging messages initialized at level 64
ODPI [227043] 2024-06-26 16:32:41.529: Context Parameters:
ODPI [227043] 2024-06-26 16:32:41.529: Oracle Client Lib Dir: /Users/matepalocska/instantclient_19_8_x86_64
ODPI [227043] 2024-06-26 16:32:41.529: Oracle Client Config Dir: /Users/matepalocska/instantclient_23_3_arm64/network/admin
ODPI [227043] 2024-06-26 16:32:41.529: Environment Variables:
ODPI [227043] 2024-06-26 16:32:41.529: ORACLE_HOME => "/Users/matepalocska/instantclient_23_3_arm64"
ODPI [227043] 2024-06-26 16:32:41.529: TNS_ADMIN => "/Users/matepalocska/instantclient_23_3_arm64/network/admin"
ODPI [227043] 2024-06-26 16:32:41.529: load in parameter directory
ODPI [227043] 2024-06-26 16:32:41.529: load in dir /Users/matepalocska/instantclient_19_8_x86_64
ODPI [227043] 2024-06-26 16:32:41.529: load with name /Users/matepalocska/instantclient_19_8_x86_64/libclntsh.dylib
ODPI [227043] 2024-06-26 16:32:41.839: load by OS successful
ODPI [227043] 2024-06-26 16:32:41.839: validating loaded library
(datetime.datetime(2024, 6, 26, 9, 32, 43),)

@matepalocska Are you able to connect to this Database using SQL*Plus via this Instant Client?

@matepalocska Are you able to connect to this Database using SQL*Plus via this Instant Client?

Yes, I can connect and run queries with SQL*Plus.

@matepalocska We will try to internally replicate this issue and get back to you.

@matepalocska Can you try upgrading your python version to 3.12 and run this test case?

@sharadraju Seems like the python version upgrade helped.

My latest results are:

platform.platform: macOS-14.5-arm64-arm-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.12.4
oracledb.version: 2.2.1
current machine is ARM64
ODPI [354498] 2024-06-27 11:32:20.218: ODPI-C 5.2.0
ODPI [354498] 2024-06-27 11:32:20.218: debugging messages initialized at level 64
ODPI [354498] 2024-06-27 11:32:20.218: Context Parameters:
ODPI [354498] 2024-06-27 11:32:20.218: Oracle Client Lib Dir: /Users/matepalocska/instantclient_23_3_arm64
ODPI [354498] 2024-06-27 11:32:20.218: Oracle Client Config Dir: /Users/matepalocska/instantclient_23_3_arm64/network/admin
ODPI [354498] 2024-06-27 11:32:20.218: Environment Variables:
ODPI [354498] 2024-06-27 11:32:20.218: ORACLE_HOME => "/Users/matepalocska/instantclient_23_3_arm64"
ODPI [354498] 2024-06-27 11:32:20.218: TNS_ADMIN => "/Users/matepalocska/instantclient_23_3_arm64/network/admin"
ODPI [354498] 2024-06-27 11:32:20.219: load in parameter directory
ODPI [354498] 2024-06-27 11:32:20.219: load in dir /Users/matepalocska/instantclient_23_3_arm64
ODPI [354498] 2024-06-27 11:32:20.219: load with name /Users/matepalocska/instantclient_23_3_arm64/libclntsh.dylib
ODPI [354498] 2024-06-27 11:32:20.530: load by OS successful
ODPI [354498] 2024-06-27 11:32:20.530: validating loaded library
(datetime.datetime(2024, 6, 27, 4, 32, 22),)

Thanks for the suggestion!

This base issue is that Oracle Client libraries require a certain level of OpenSSL, which the older Python versions don't have.
I had a "discussion" with some developers yesterday about catching the error and printing a useful error, but whether that is possible is yet to be determined by the group that owns the relevant code layer. For tracking purposes, you can reference Oracle bug 36790189.

Since this problem isn't in python-oracledb itself, I'll close this issue. Thanks for reporting it.

Instant Client 23.3 Basic & Basic Light packages for macOS ARM were patched, so older Pythons on macOS work now. Look for the *-1.dmg files.