This bug only exists in thick mode, not thin mode.
Getting a type from the database requires a relatively expensive round trip:
r_rec := conn.gettype('TEST_FOO_PKG.R_REC')
If you have a web server with a connection pool, it would be ideal to create one type at application launch that can be shared between all connections. This way you don't have the performance hit of having to instantiate a new type for each web request.
With thin mode, we can share a type between multiple connections.
With thick mode, this results in ORA-21779: duration not active. I'm using AQ and some other features and cannot switch to thin mode unfortunately.
Would you folks please take a look? Thank you.
CREATE OR REPLACE PACKAGE test_foo_pkg
IS
TYPE r_rec IS RECORD (
bar varchar2(128)
);
FUNCTION baz
RETURN r_rec;
END test_foo_pkg;
/
CREATE OR REPLACE PACKAGE BODY test_foo_pkg
IS
FUNCTION baz
RETURN r_rec
IS
l_rec r_rec;
BEGIN
l_rec.bar := 'hello';
RETURN l_rec;
END baz;
END test_foo_pkg;
/
import contextlib
import oracledb
from datetime import datetime
oracledb.init_oracle_client()
assert not oracledb.is_thin_mode()
conn1 = oracledb.connect('user/password@db')
conn2 = oracledb.connect('user/password@db')
r_rec = conn1.gettype('TEST_FOO_PKG.R_REC')
# First connection
cursor1 = conn1.cursor()
l_rec = cursor1.callfunc('TEST_FOO_PKG.BAZ', r_rec)
assert l_rec.BAR == 'hello'
cursor1.close()
# Second connection, attempt to reuse type r_rec
cursor2 = conn2.cursor()
# This raises Connections ORA-21779: duration not active
l_rec = cursor2.callfunc('TEST_FOO_PKG.BAZ', r_rec)
On thin mode it works without issue:
assert oracledb.is_thin_mode
...
l_rec = cursor2.callfunc('TEST_FOO_PKG.BAZ', r_rec)
assert l_rec.BAR == 'hello'
- What versions are you using?
Oracle Database 19.25.0.0.0
OCI 19.25
platform.platform: Windows-11-10.0.22631-SP0
sys.maxsize > 2**32: True
platform.python_version: 3.13.0
oracledb.version: 2.5.1
oracledb.clientversion(): (19, 25, 0, 0, 0)
Give your database version.
- Is it an error or a hang or a crash?
Error
- What error(s) or behavior you are seeing?
ORA-21779: duration not active
- Does your application call init_oracle_client()?
Yes, thick mode.
- Include a runnable Python script that shows the problem.
Please see above.
This bug only exists in thick mode, not thin mode.
Getting a type from the database requires a relatively expensive round trip:
If you have a web server with a connection pool, it would be ideal to create one type at application launch that can be shared between all connections. This way you don't have the performance hit of having to instantiate a new type for each web request.
With thin mode, we can share a type between multiple connections.
With thick mode, this results in
ORA-21779: duration not active. I'm using AQ and some other features and cannot switch to thin mode unfortunately.Would you folks please take a look? Thank you.
On thin mode it works without issue:
Oracle Database 19.25.0.0.0
OCI 19.25
platform.platform: Windows-11-10.0.22631-SP0
sys.maxsize > 2**32: True
platform.python_version: 3.13.0
oracledb.version: 2.5.1
oracledb.clientversion(): (19, 25, 0, 0, 0)
Give your database version.
Error
ORA-21779: duration not active
Yes, thick mode.
Please see above.