Unhelful error message when accessing connection attributes in subclass constructor · Issue #385 · oracle/python-oracledb (original) (raw)
- What versions are you using?
database: 21 XE
platform.platform: macOS-14.6.1-arm64-arm-64bit
sys.maxsize > 2**32: True
platform.python_version: 3.12.4
oracledb.version: 2.4.1
- Is it an error or a hang or a crash?
An exception happens when I access certain attributes in the constructor of a Connection
subclass before calling the base class' __init__
.
- What error(s) or behavior you are seeing?
The following Python code:
import oracledb
class C(oracledb.Connection): def init(self, *args, **kwargs): self.outputtypehandler = None super().init(self, *args, **kwargs)
db = C("user/pwd@db")
results in the following output:
Traceback (most recent call last):
File "/Users/walter/checkouts/LivingLogic.Python.xist/oracledb_issue.py", line 9, in <module>
db = C("user/pwd@db")
^^^^^^^^^^^^^^^^
File "/Users/walter/checkouts/LivingLogic.Python.xist/oracledb_issue.py", line 5, in __init__
self.outputtypehandler = None
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/walter/pyvenvs/default/lib/python3.12/site-packages/oracledb/connection.py", line 376, in outputtypehandler
self._verify_connected()
File "/Users/walter/pyvenvs/default/lib/python3.12/site-packages/oracledb/connection.py", line 85, in _verify_connected
if self._impl is None:
^^^^^^^^^^
AttributeError: 'C' object has no attribute '_impl'
Exception ignored in: <function Connection.__del__ at 0x106208cc0>
Traceback (most recent call last):
File "/Users/walter/pyvenvs/default/lib/python3.12/site-packages/oracledb/connection.py", line 568, in __del__
if self._impl is not None:
^^^^^^^^^^
AttributeError: 'C' object has no attribute '_impl'
I realize that this is probably a borderline use and a fix for the code is simple: Move setting the outputtypehandler
attribute after the call to the base class' __init__
. However the stacktrace (and the fact, that a second exception happens in __del__
) suggests that oracledb
's code seems to be unprepared for such cases, so it might be good to look into that problem nonetheless.
- Does your application call init_oracle_client()?
No.
- Include a runnable Python script that shows the problem.
See above.