Opened 3 years ago

Last modified 2 years ago

#22144 new Bug

Oracle Long text and bulk_create

Reported by: artur@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords: oracle bulk_create
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I'm using django 1.6.2 + oracle 12 + cx_oracle 5.1.2

here is my model

class Value(models.Model):
    text= models.TextField()

I have some text and it's length is 3000 characters in Russian language, when im tring to do that:

text = 'some text' #3000 characters

v = Value(text=text)

it's ok ...

but when i'm doing that:

text = 'some text' #3000 characters

v = Value(text=text)

I got this exception:


Request Method: GET
Request URL:

Django Version: 1.6.2
Python Version: 3.3.4
Installed Applications:
Installed Middleware:

File "C:\Python33\lib\site-packages\django\core\handlers\" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\user\PycharmProjects\tpp\tppcenter\" in test
  374.     Value.objects.bulk_create([v])
File "C:\Python33\lib\site-packages\django\db\models\" in bulk_create
  160.         return self.get_queryset().bulk_create(*args, **kwargs)
File "C:\Python33\lib\site-packages\django\db\models\" in bulk_create
  356.                     self._batched_insert(objs_without_pk, fields, batch_size)
File "C:\Python33\lib\site-packages\django\db\models\" in _batched_insert
  835.                                              using=self.db)
File "C:\Python33\lib\site-packages\django\db\models\" in _insert
  232.         return insert_query(self.model, objs, fields, **kwargs)
File "C:\Python33\lib\site-packages\django\db\models\" in insert_query
  1511.     return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python33\lib\site-packages\django\db\models\sql\" in execute_sql
  899.             cursor.execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\backends\" in execute
  69.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\backends\" in execute
  53.                 return self.cursor.execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\" in __exit__
  99.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python33\lib\site-packages\django\utils\" in reraise
  535.             raise value.with_traceback(tb)
File "C:\Python33\lib\site-packages\django\db\backends\" in execute
  53.                 return self.cursor.execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\backends\oracle\" in execute
  815.             return self.cursor.execute(query, self._param_generator(params))

Exception Type: DatabaseError at /test/
Exception Value: ORA-01461: can bind a LONG value only for insert into a LONG column

Change History (4)

comment:1 Changed 3 years ago by artur@…

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Hmmm... I can insert larger rando text of 10k characters ...
But if I cut the text to 3000 ( my text is 2935 characters ) then I got this exception ...

Seems like a bug in oracle segmentation algorithm when using bulk insert?

comment:2 Changed 3 years ago by Daniele Procida

Summary: Oralce Long text and bulk_createOracle Long text and bulk_create
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 Changed 2 years ago by anonymous

I get the same problem: my input is 2948 character long and fails with the same error. As a workaround, I applied this ugly patch:

--- a/libs/project-packages/django/db/backends/oracle/
+++ b/libs/project-packages/django/db/backends/oracle/
@@ -616,7 +616,7 @@ class OracleParam(object):
         if hasattr(param, 'input_size'):
             # If parameter has `input_size` attribute, use that.
             self.input_size = param.input_size
-        elif isinstance(param, six.string_types) and len(param) > 4000:
+        elif isinstance(param, six.string_types) and len(param) > 2000:
             # Mark any string param greater than 4000 characters as a CLOB.
             self.input_size = Database.CLOB

My django version is 1.5.5.

comment:4 in reply to:  3 Changed 2 years ago by aurelien.scoubeau+trac@…

Replying to myself to give a name.

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