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
https://oracle.github.io/python-oracledb
Other
307 stars 59 forks source link

Internal exception raised when DSN connection string is badly formatted #339

Closed nmoreaud closed 1 month ago

nmoreaud commented 1 month ago

If I try to connect to an Oracle server and my connection string is badly formatted (here ADRESS instead of ADDRESS), oracledb raises an internal exception. (note oracledb before 2.0 crashes with a segfault)

sys.maxsize > 2**32: True
platform.python_version: 3.11.8
oracledb.__version__: 2.2.0

Ex:

import oracledb

con = oracledb.connect(
    dsn='(DESCRIPTION=(ADRESS=(PROTOCOL=TCP)(HOST=123.123.123.123)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=SERVER.COMPANY.com)))',
    user='myuser', password='mypassword'
)
cur = con.cursor()

cur.execute("select 1 from dual")
row = cur.fetchone()
print(row)
Traceback (most recent call last):
  File "test_oracledb.py", line 9, in <module>
    cur.execute("select 1 from dual")
  File ".venv/lib/python3.11/site-packages/oracledb/cursor.py", line 701, in execute
    impl.execute(self)
  File "src/oracledb/impl/thin/cursor.pyx", line 178, in oracledb.thin_impl.ThinCursorImpl.execute
  File "src/oracledb/impl/thin/protocol.pyx", line 438, in oracledb.thin_impl.Protocol._process_single_message
  File "src/oracledb/impl/thin/protocol.pyx", line 439, in oracledb.thin_impl.Protocol._process_single_message
  File "src/oracledb/impl/thin/protocol.pyx", line 400, in oracledb.thin_impl.Protocol._process_message
  File "src/oracledb/impl/thin/protocol.pyx", line 377, in oracledb.thin_impl.Protocol._process_message
  File "src/oracledb/impl/thin/messages.pyx", line 319, in oracledb.thin_impl.Message.send
  File "src/oracledb/impl/thin/packet.pyx", line 780, in oracledb.thin_impl.WriteBuffer.end_request
  File "src/oracledb/impl/thin/packet.pyx", line 753, in oracledb.thin_impl.WriteBuffer._send_packet
  File "src/oracledb/impl/thin/transport.pyx", line 348, in oracledb.thin_impl.Transport.write_packet
AttributeError: 'NoneType' object has no attribute 'send'
nmoreaud commented 1 month ago

It happens for ADDRESS and DESCRIPTION fields.

anthony-tuininga commented 1 month ago

Thanks. I can replicate the issue. I'll let you know when I have discovered the source of the issue!

anthony-tuininga commented 1 month ago

Good news! I was able to correct the issue and have pushed a patch that corrects it. If you are able to build from source you can verify that it works for you, too.

nmoreaud commented 1 month ago

Very nice, thanks. Do you also maintain a more "stable" version 1.X branch? If so I would greatly appreciate a fix in this branch too. I am going to test your fix on Monday if I have the opportunity.

anthony-tuininga commented 1 month ago

2.2.x is considered stable! So I have no plans to add to any of the v1 branches or to create another v1 patch. Is there a reason you are avoiding v2.x?

nmoreaud commented 1 month ago

Okay, I will test if my application works fine with the latest version

nmoreaud commented 1 month ago

The fix works fine for me

anthony-tuininga commented 1 month ago

This was included in version 2.2.1 which was just released.