Using `appcontext` with SessionPool
- What versions are you using?
cx_Oracle 8.0.1
>>> import sys
>>> import platform
>>>
>>> print("platform.platform:", platform.platform())
platform.platform: Linux-4.18.0-193.29.1.el8_2.x86_64-x86_64-with-centos-7.9.2009-Core
>>> print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
sys.maxsize > 2**32: True
>>> print("platform.python_version:", platform.python_version())
platform.python_version: 3.6.9
>>> import cx_Oracle
>>> print("cx_Oracle.version:", cx_Oracle.version)
cx_Oracle.version: 8.0.1
>>> print("cx_Oracle.clientversion:", cx_Oracle.clientversion())
cx_Oracle.clientversion: (19, 9, 0, 0, 0)
- Describe the problem
When I want to get a connection using cx_Oracle.connection(..., appcontext=CTX_ENTRIES), I succesfully see that context entries are applied.
But when I want to use a connection pool, I was unable to find a way to provide an appcontext.
So my question is, is there a way to provide appcontext when using SessionPool, such as:
pool = cx_Oracle.SessionPool(..., appcontext=CTX_ENTRIES)
There doesn't seem to be a direct way.
Is calling DBMS_SESSION.SET_CONTEXT in a pool sessionCallback function usable?
What are you using contexts for?
What are you using contexts for?
We have a LOGON TRIGGER on our production database that performs certain validations, one of them expecting the sys_context('USERENV', 'OS_USER') to be a certain value. Due to some operational challenges, I cannot rely on the username cx_Oracle resolves, and need to override it.
Is calling DBMS_SESSION.SET_CONTEXT in a pool sessionCallback function usable?
Since I cannot get past the logon trigger, I assumed the sessionCallback would not work. I've performed some tests now, and they did not work out for me.
What I tried was to create a simple all denying logon trigger like this one and use sessionCallback:
CREATE OR REPLACE TRIGGER test_logon_trigger
AFTER LOGON
ON SOME.SCHEMA
BEGIN
raise_application_error(-20001, 'You cannot connect, your os_user is ' || sys_context('USERENV', 'OS_USER') || '');
END;
/
EDIT:
Just to give a better idea about the requirement I have, when using the JDBC driver we set -Doracle.jdbc.v$session.osuser=XXXXXX to override the required context. If there is a way to override this on oracle client level, maybe that would work out for me as well.
Hello ,
were you able to resolve the issue? I am facing same case
Thanks
Hello ,
were you able to resolve the issue? I am facing same case
Thanks
Unfortunately no, not at the time of discussion. We went ahead with an internal workaround that is not relevant to this issue.
Python-oracledb 2.5 added support for this in Thin mode. See https://python-oracledb.readthedocs.io/en/latest/api_manual/module.html#oracledb.create_pool and https://python-oracledb.readthedocs.io/en/latest/release_notes.html#oracledb-2-5-0-november-2024 and