-
Notifications
You must be signed in to change notification settings - Fork 61
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
cursor.execute() fails when fetching from table with NCLOB column and IS JSON check. #271
Comments
Thanks for the report. |
(My definition of a crash is something like a seg fault, so I will take the liberty of changing the subject, if you don't mind !) Though I wouldn't have expected the error you are seeing, you may ultimately have encountered the python-oracledb 2.0 change in default handling of columns with IS JSON constraints. See the release notes and deprecations and release announcement. In python-oracledb 2.0 if you still want to fetch IS JSON columns stored in BLOBs as, e.g. a Lob instead of as an object, then use an output type handler:
This gives me:
I wonder if the error you posted could perhaps be as a result of executing the same SQL statement but with different types? |
Thanks. Adding the following: diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index a5e7f97df0..8b93d871bb 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -483,6 +483,8 @@ class FormatStylePlaceholderCursor:
arraysize=cursor.arraysize,
outconverter=outconverter,
)
+ elif defaultType == Database.DB_TYPE_NCLOB:
+ return cursor.var(Database.DB_TYPE_NCLOB, arraysize=cursor.arraysize)
def _format_params(self, params):
try: fixes this issue for me. However, it still looks like an issue in |
@felixxm is it crashing in your test suite? |
Yes, with
I still don't understand why. We don't even fetch results, but adding a no-op converter fixes this issue. |
@felixxm Can you please point me to the particular test which is failing with IndexError: list index out of range in the django test suite. |
It's diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 5c2ed53db8..b6ae45705f 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -118,6 +118,7 @@ class Command(BaseCommand):
cursor, table_name
)
except Exception as e:
+ raise
yield "# Unable to inspect table '%s'" % table_name
yield "# The error was: %s" % e
continue
|
@felixxm My general concern is how Django is handling Oracle DB 21c's new JSON column type, since that will be returned by python-oracledb as the kind of object that columns with the IS JSON constraint now return by default. I also asked @suraj-ora-2020 to look into this. (And one day we need to get Django to stop using NCLOB!) |
So, it turns out the issue has nothing to do with NCLOB at all! The problem is due to the following complex sequence of events:
The only reason the NCLOB column with an IS JSON constraint is relevant is because internally a fetch variable is created with an output converter. You can see the test case in the patch for an alternative way of generating the issue. |
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. |
The patch has been included in version 2.0.1 which was just released. |
cursor.execute()
crashes when fetching from table withNCLOB
column andIS JSON
check. The following SQL crashes in Django:(it works with the 1.4.2 version).
Table definition:
Oracle 23c (crashes the same way on Oracle 19c).
crash
No
I was not able to reproduce it with the bare
oracledb
cursor or Django cursor, but it crashes in our test suite. Maybe previousfetchall()
,fetchone()
,execute()
calls affect it somehow 🤔 🤯The text was updated successfully, but these errors were encountered: