Opened 2 years ago

Closed 2 years ago

#33339 closed Bug (fixed)

bulk_create() uses TO_CLOB() for NCLOB fields on Oracle.

Reported by: Georgi Yanchev Owned by: Georgi Yanchev
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords: oracle
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the model, containing one TextField

from django.db import models

class Bar(models.Model):
    baz = models.TextField()

When you make a bulk_create request, e.g. Bar.objects.bulk_create([b0, b1]) you will get generate a query like below.

INSERT INTO "PROJECT_BAR" ("BAZ") SELECT * FROM (SELECT TO_CLOB(:arg1) col_0 FROM DUAL UNION ALL SELECT TO_CLOB(:arg0) FROM DUAL)

This will be accepted by Oracle, but it will create a log file, named something like DBNAME_ora_6613.trc, which contains errors:

ORA-12704(1): dty=112 typ=1 flg=00220000 xfl=00040000 bfl=4000 bfc=0 csfm=2 csid=2000 csflg=0 collid=16382 cclvl=2
ORA-12704(2): dty=112 typ=2 flg=00230000 xfl=00000000 bfl=4000 bfc=0 csfm=1 csid=873 csflg=0 collid=16382 cclvl=3 op=184 opc=1
ORA-12704(2): dty=1 typ=3 flg=00030081 xfl=00040000 bfl=2000 bfc=2000 csfm=1 csid=873 csflg=0 collid=16382 cclvl=3 styp=1

The problem is that field PROJECT_BAR.BAZ is of type NCLOB, but Django uses TO_CLOB, instead of TO_NCLOB.

Change History (2)

comment:1 by Mariusz Felisiak, 2 years ago

Component: UncategorizedDatabase layer (models, ORM)
Has patch: set
Keywords: oracle added
Owner: changed from nobody to Georgi Yanchev
Status: newassigned
Summary: TO_CLOB is used for NCLOB fields in Oraclebulk_create() uses TO_CLOB() for NCLOB fields on Oracle.
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Thanks for the report.

PR

comment:2 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 9c1fe446:

Fixed #33339 -- Made QuerySet.bulk_create() use TO_NCLOB() for TextFields on Oracle.

Note: See TracTickets for help on using tickets.
Back to Top