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

Cannot set NULL on DbObject attribute any more in 2.0 #273

Closed
mkmoisen opened this issue Dec 20, 2023 · 4 comments
Closed

Cannot set NULL on DbObject attribute any more in 2.0 #273

mkmoisen opened this issue Dec 20, 2023 · 4 comments
Labels
bug Something isn't working patch available

Comments

@mkmoisen
Copy link

In 2.0 it is no longer possible to set an attribute on DbObject to NULL for a VARCHAR2.

This was possible in all previous versions of oracledb as well as cx_Oracle.

This bug was caused by the following change:

8211232

The change assumes that the value is not null.

There needs to be a condition that checks if it is null and then avoids performing this max size check, for example:

        if value is not None and max_size > 0:
            if isinstance(value, str):
                actual_size[0] = len((<str> value).encode())
            else:
                actual_size[0] = len(<bytes> value)
            if actual_size[0] > max_size:
                violated[0] = True
  1. What versions are you using?

2.0

Give your database version.

19C

Also run Python and show the output of:

>>> import sys
>>> import platform
>>> 
>>> print("platform.platform:", platform.platform())
platform.platform: Linux-4.18.0-372.76.1.el8_6.x86_64-x86_64-with-glibc2.28
>>> 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.12.1

And:

>>> import oracledb
>>> print("oracledb.__version__:", oracledb.__version__)
oracledb.__version__: 2.0.0
  1. Is it an error or a hang or a crash?

error

  1. What error(s) or behavior you are seeing?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/app-root/lib/python3.12/site-packages/oracledb/dbobject.py", line 60, in __setattr__
    self._impl.set_attr_value(attr_impl, value)
  File "src/oracledb/impl/base/dbobject.pyx", line 123, in oracledb.base_impl.BaseDbObjectImpl.set_attr_value
  File "src/oracledb/impl/base/dbobject.pyx", line 44, in oracledb.base_impl.BaseDbObjectImpl._check_max_size
TypeError: object of type 'NoneType' has no len()

Cut and paste text showing the command you ran. No screenshots.

Here is the PLSQL to create the record:


create or replace package foo_pkg
is
    type r_bar IS RECORD (baz varchar2(10));
end foo_pkg;
/

create or replace package body foo_pkg
is
    
end foo_pkg;
/

Here is the python that creates an instance of the record type and set BAZ to null:

r_foo_type = conn.gettype('MY_SCHEMA.FOO_PKG.R_BAR')

r_foo = r_foo_type.newobject()

# This is OK, as expected
r_foo.BAZ = 'hi'

# Setting to NULL results in an error:
r_foo.BAZ = None

Here is the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/app-root/lib/python3.12/site-packages/oracledb/dbobject.py", line 60, in __setattr__
    self._impl.set_attr_value(attr_impl, value)
  File "src/oracledb/impl/base/dbobject.pyx", line 123, in oracledb.base_impl.BaseDbObjectImpl.set_attr_value
  File "src/oracledb/impl/base/dbobject.pyx", line 44, in oracledb.base_impl.BaseDbObjectImpl._check_max_size
TypeError: object of type 'NoneType' has no len()
  1. Does your application call init_oracle_client()?

Yes, thick mode.

This tells us whether you are using the python-oracledb Thin or Thick mode.

@mkmoisen mkmoisen added the bug Something isn't working label Dec 20, 2023
@cjbj
Copy link
Member

cjbj commented Dec 20, 2023

Thanks for the report and analysis.

anthony-tuininga added a commit that referenced this issue Jan 2, 2024
attributes or used as elements of collections (#273).
@anthony-tuininga
Copy link
Member

I have pushed a patch that should correct this bug. If you are able to build from source you can verify that it works for you.

@anthony-tuininga
Copy link
Member

The patch has been included in version 2.0.1 which was just released.

@mkmoisen
Copy link
Author

mkmoisen commented Jan 9, 2024

@anthony-tuininga Sorry I missed your message. I just tried 2.0.1 and my regression tests are passing now. Thanks!

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

3 participants