Opened 14 minutes ago
#37506 new Bug
Oracle "executemany()" fails with mixed-length strings in Django 6.1.3, but works in Django 6.1.2
| Reported by: | pm13 | Owned by: | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 6.1 |
| Severity: | Normal | Keywords: | |
| Cc: | pm13 | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Description
I encountered a regression after upgrading Django from 6.1.2 to 6.1.3.
I use cursor.executemany() to insert data into an Oracle table. One of the columns is defined as VARCHAR2(8000) and some values exceed 4000 characters.
The same code works with Django 6.1.2 but fails with Django 6.1.3.
Environment
- Django: 6.1.3 (works with 6.1.2)
- python-oracledb: 26.1.0
- Oracle database with
MAX_STRING_SIZE=EXTENDED - Target column:
VARCHAR2(8000)
Steps to reproduce
Create a table:
CREATE TABLE django_lob_test (
id NUMBER(10) NOT NULL PRIMARY KEY,
text_value VARCHAR2(8000)
);
Run the following code using Django's database connection:
from django.db import connection small_text = "s" * 3500 large_text = "L" * 4199 rows = [ [100, small_text], [101, large_text], ] with connection.cursor() as cursor: cursor.executemany( "INSERT INTO django_lob_test (id, text_value) VALUES (%s, %s)", rows, )
Actual results
With Django 6.1.3, the operation fails with:
oracledb.exceptions.NotSupportedError: DPY-3013: unsupported Python type LOB for database type DB_TYPE_VARCHAR
Reversing the order of the rows produces a different error:
oracledb.exceptions.NotSupportedError: DPY-3013: unsupported Python type str for database type DB_TYPE_CLOB
Additional tests
I also tested the same inserts using the native python-oracledb cursor:
raw_cursor = connection.connection.cursor() raw_cursor.executemany( "INSERT INTO django_lob_test (id, text_value) VALUES (:1, :2)", rows, ) raw_cursor.close()
Both row orders work successfully with the native cursor:
- Short string first, long string second: SUCCESS
- Long string first, short string second: SUCCESS
The issue does not occur with Django 6.1.2.
Possible relation to #37411
I noticed that Django 6.1.3 includes the fix for #37411 – Add support for python-oracledb version 26.
Looking at the changes in that ticket, I noticed that OracleParam now converts strings longer than 4000 bytes into temporary LOB objects using cursor.connection.createlob().
I wonder if this change could be related to the issue, as the batch appears to contain a mixture of regular Python strings and LOB objects. I have not investigated the Django implementation in enough detail to confirm this, but thought it might be a useful starting point.