Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOB.read(0) gives unhelpful error message in thin mode #13

Closed
doerwalter opened this issue Jun 8, 2022 · 4 comments
Closed

LOB.read(0) gives unhelpful error message in thin mode #13

doerwalter opened this issue Jun 8, 2022 · 4 comments
Labels
bug Something isn't working patch available

Comments

@doerwalter
Copy link

The following Python script:

import oracledb
db = oracledb.connect("user/pwd@db")
c = db.cursor()
c.execute("select to_clob('foo') from dual").fetchone()[0].read(0)

gives the following output:

Traceback (most recent call last):
  File "/Users/walter/oracledb_bug.py", line 4, in <module>
    c.execute("select to_clob('foo') from dual").fetchone()[0].read(0)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/oracledb/lob.py", line 116, in read
    return self._impl.read(offset, amount)
  File "src/oracledb/impl/thin/lob.pyx", line 140, in oracledb.thin_impl.ThinLobImpl.read
  File "src/oracledb/impl/thin/protocol.pyx", line 294, in oracledb.thin_impl.Protocol._process_single_message
  File "src/oracledb/impl/thin/protocol.pyx", line 295, in oracledb.thin_impl.Protocol._process_single_message
  File "src/oracledb/impl/thin/protocol.pyx", line 288, in oracledb.thin_impl.Protocol._process_message
oracledb.exceptions.DatabaseError: ORA-03137: malformed TTC packet from client rejected: [kpolob:offset 0] [0] [0] [2] [] [] [] []

In thick mode I get:

Traceback (most recent call last):
  File "/Users/walter/oracledb_bug.py", line 5, in <module>
    c.execute("select to_clob('foo') from dual").fetchone()[0].read(0)
  File "/Users/walter/pyvenvs/default/lib/python3.10/site-packages/oracledb/lob.py", line 116, in read
    return self._impl.read(offset, amount)
  File "src/oracledb/impl/thick/lob.pyx", line 168, in oracledb.thick_impl.ThickLobImpl.read
  File "src/oracledb/impl/thick/utils.pyx", line 409, in oracledb.thick_impl._raise_from_odpi
  File "src/oracledb/impl/thick/utils.pyx", line 399, in oracledb.thick_impl._raise_from_info
oracledb.exceptions.DatabaseError: ORA-24801: Unzulässiger Parameterwert in OCI-LOB-Funktion

which at least gives a hint at what the problem is.

import sys, platform, oracledb

print(f"{platform.platform()=}")
print(f"{sys.maxsize > 2**32=}")
print(f"{platform.python_version()=}")
print(f"{oracledb.__version__=}")

prints

platform.platform()='macOS-12.4-x86_64-i386-64bit'
sys.maxsize > 2**32=True
platform.python_version()='3.10.4'
oracledb.__version__='1.0.0'

The database is an Oracle XE.

select value from nls_database_parameters where parameter='NLS_RDBMS_VERSION';

returns 21.0.0.0.0.

@doerwalter doerwalter added the bug Something isn't working label Jun 8, 2022
@anthony-tuininga
Copy link
Member

If we adjust the code so that it returns an empty string instead of raising an exception, would you consider that preferable? I don't find the thick driver error to be all that helpful either! The other option is to create a more meaningful error -- but it seems unnecessary. Thoughts?

@doerwalter
Copy link
Author

The most helpful would probably be:

ValueError: offset must be > 0

BTW, passing a negative values currently results in:

OverflowError: can't convert negative value to uint64_t

so 0 is the only values with this behavour.

The most elegant API would be support for slices for LOB objects, since slices clip out of bound values automatically.

So instead of lob.read(1, 100) I could do lob[:100] and instead of lob.read(lob.getsize()-100) I could do lob[-100:] (I'm assuming that the default value for the amount parameter is "until the rest of the LOB".

anthony-tuininga added a commit that referenced this issue Jul 20, 2022
when the offset parameter to LOB.read() is zero or negative (#13).
@anthony-tuininga
Copy link
Member

I've added error DPY-2030 to address this situation for both thin and thick. If you want to create a new enhancement request for supporting slices with LOBs, please go ahead; otherwise, I'll close this when 1.1 is released.

@anthony-tuininga
Copy link
Member

This enhancement has been implemented in python-oracledb 1.1.0 which was just released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch available
Projects
None yet
Development

No branches or pull requests

2 participants