#30510 closed Bug (fixed)
bulk_create() crashes with mixed length arguments on LOB fields on Oracle.
Reported by: | Mark Gordon | Owned by: | Ahmet Kucuk |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | oracle bulk_create |
Cc: | Georgi Yanchev | 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 below model, containing one LOB field
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 :arg1 col_0 FROM DUAL UNION ALL SELECT :arg0 FROM DUAL)
This works most of the time, however at some point logic was added to automatically convert a string's type to Database.CLOB
when it exceeded 4000 bytes from a normal string literal type. When this conversion happens for some of the arguments but not all of the arguments in the ephemeral table Oracle will complain that the type of the column of the unified table is inconsistent and fail the query.
E.g. the following will fail
Bar.objects.bulk_create([Bar(baz='aaa'), Bar(baz='a'*5000)])
Generating the error
django.db.utils.DatabaseError: ORA-01790: expression must have same datatype as corresponding expression
Note that when both objects have a long or both have a short baz
field this query succeeds.
I'm working on a patch
Change History (6)
comment:1 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 6 years ago
Has patch: | set |
---|---|
Keywords: | oracle bulk_create added |
Summary: | Bulk creates with Oracle backend fail with mixed length arguments on LOB field → bulk_create() crashes with mixed length arguments on LOB fields on Oracle. |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
Version: | 2.1 → master |
comment:6 by , 5 years ago
Cc: | added |
---|
Thanks for the report. Reproduced at 1d25354fb5f87d35968cd78b53d9560fd75f5b1a.
PR