mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
[3.0.x] Fixed #30510 -- Fixed crash of QuerySet.bulk_create() with mixed-length texts on Oracle.
Text with more than 4000 characters must be set to as a CLOB on Oracle what caused a mixed datatype error (ORA-01790) when shorter text appeared in the same operation. Backport of dc890bef5ad8e9fccce55f3e64af72103ea6e8c1 from master
This commit is contained in:
parent
a135e1e16e
commit
9dc13f41b5
@ -51,6 +51,7 @@ class Oracle_datetime(datetime.datetime):
|
|||||||
|
|
||||||
class BulkInsertMapper:
|
class BulkInsertMapper:
|
||||||
BLOB = 'TO_BLOB(%s)'
|
BLOB = 'TO_BLOB(%s)'
|
||||||
|
CBLOB = 'TO_CLOB(%s)'
|
||||||
DATE = 'TO_DATE(%s)'
|
DATE = 'TO_DATE(%s)'
|
||||||
INTERVAL = 'CAST(%s as INTERVAL DAY(9) TO SECOND(6))'
|
INTERVAL = 'CAST(%s as INTERVAL DAY(9) TO SECOND(6))'
|
||||||
NUMBER = 'TO_NUMBER(%s)'
|
NUMBER = 'TO_NUMBER(%s)'
|
||||||
@ -70,5 +71,6 @@ class BulkInsertMapper:
|
|||||||
'PositiveIntegerField': NUMBER,
|
'PositiveIntegerField': NUMBER,
|
||||||
'PositiveSmallIntegerField': NUMBER,
|
'PositiveSmallIntegerField': NUMBER,
|
||||||
'SmallIntegerField': NUMBER,
|
'SmallIntegerField': NUMBER,
|
||||||
|
'TextField': CBLOB,
|
||||||
'TimeField': TIMESTAMP,
|
'TimeField': TIMESTAMP,
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,16 @@ class BulkCreateTests(TestCase):
|
|||||||
Country.objects.bulk_create([Country(description='Ж' * 3000)])
|
Country.objects.bulk_create([Country(description='Ж' * 3000)])
|
||||||
self.assertEqual(Country.objects.count(), 1)
|
self.assertEqual(Country.objects.count(), 1)
|
||||||
|
|
||||||
|
@skipUnlessDBFeature('has_bulk_insert')
|
||||||
|
def test_long_and_short_text(self):
|
||||||
|
Country.objects.bulk_create([
|
||||||
|
Country(description='a' * 4001),
|
||||||
|
Country(description='a'),
|
||||||
|
Country(description='Ж' * 2001),
|
||||||
|
Country(description='Ж'),
|
||||||
|
])
|
||||||
|
self.assertEqual(Country.objects.count(), 4)
|
||||||
|
|
||||||
def test_multi_table_inheritance_unsupported(self):
|
def test_multi_table_inheritance_unsupported(self):
|
||||||
expected_message = "Can't bulk create a multi-table inherited model"
|
expected_message = "Can't bulk create a multi-table inherited model"
|
||||||
with self.assertRaisesMessage(ValueError, expected_message):
|
with self.assertRaisesMessage(ValueError, expected_message):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user