Can not create a connection pool with a proxy user while this is possible in cx_Oracle. · Issue #101 · oracle/python-oracledb (original) (raw)

  1. What versions are you using?

database: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

platform.platform: macOS-10.16-x86_64-i386-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.9.5
oracledb.version: 1.2.0

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

error

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

I am displaying the number 1, session user and proxy user for three different connection types (self describing below):

This the output:

test_oracledb_connect
(1, 'BC_BO', 'BC_PROXY')
test_oracledb_create_pool
(1, 'BC_PROXY', None)
test_cx_oracle_sessionpool
(1, 'BC_BO', 'BC_PROXY')

  1. Does your application call init_oracle_client()?

Yes

  1. Include a runnable Python script that shows the problem.
import os
import oracledb
import cx_Oracle


PROXY_USER = 'BC_PROXY'
SESSION_USER = 'BC_BO'
USER = f"{PROXY_USER}[{SESSION_USER}]"
PASSWORD = os.getenv('PASSWORD')
DSN = 'bc_acc'


def process(connection):
        with connection.cursor() as cursor:
            rs = cursor.execute("""\
select  :idx
,       sys_context('USERENV', 'SESSION_USER') as session_user
,       sys_context('USERENV', 'PROXY_USER') as proxy_user
from    dual""", idx=1)
            if rs:  # it is a query
                for row in rs:
                    print(row)


def test_oracledb_connect():
        print('test_oracledb_connect')
        oracledb.init_oracle_client()
        connection = oracledb.connect(user=USER,
                                      password=PASSWORD,
                                      dsn=DSN)
        process(connection)


def test_oracledb_create_pool():
        print('test_oracledb_create_pool')
        oracledb.init_oracle_client()
        pool = oracledb.create_pool(user=USER,
                                    password=PASSWORD,
                                    dsn=DSN,
                                    homogeneous=False,
                                    encoding="UTF-8")
        connection = pool.acquire()
        process(connection)


def test_cx_oracle_sessionpool():
        print('test_cx_oracle_sessionpool')
        # Basic Authentication with proxy
        pool = cx_Oracle.SessionPool(user=USER,
                                     password=PASSWORD,
                                     dsn=DSN,
                                     homogeneous=False,
                                     encoding="UTF-8")
        connection = pool.acquire()
        process(connection)
        

def main():
        test_oracledb_connect()
        test_oracledb_create_pool()
        test_cx_oracle_sessionpool()
        

if __name__ == '__main__':
        main()