#34558: QuerySet.bulk_create() crashes with Now() on Oracle.
-------------------------------------+-------------------------------------
Reporter: Mariusz | Owner: Mariusz Felisiak
Felisiak |
Type: Bug | Status: assigned
Component: Database | Version: 4.2
layer (models, ORM) |
Severity: Normal | Keywords: oracle
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
`Now()` cannot be used with `QuerySet.bulk_create()` as it uses
`CURRENT_TIMESTAMP` which returns `TIMESTAMP WITH TIME ZONE` and crashes
when wrapped with `TO_TIMESTAMP`, e.g.
{{{#!diff
diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py
index a5050c9b0b..aee0cd9996 100644
--- a/tests/bulk_create/tests.py
+++ b/tests/bulk_create/tests.py
@@ -10,7 +10,7 @@ from django.db import (
connection,
)
from django.db.models import FileField, Value
-from django.db.models.functions import Lower
+from django.db.models.functions import Lower, Now
from django.test import (
TestCase,
override_settings,
@@ -300,6 +300,19 @@ class BulkCreateTests(TestCase):
bbb = Restaurant.objects.filter(name="betty's beetroot bar")
self.assertEqual(bbb.count(), 1)
+ @skipUnlessDBFeature("has_bulk_insert")
+ def test_bulk_insert_now(self):
+ NullableFields.objects.bulk_create(
+ [
+ NullableFields(datetime_field=Now()),
+ NullableFields(datetime_field=Now()),
+ ]
+ )
+ self.assertEqual(
+
NullableFields.objects.filter(datetime_field__isnull=False).count(),
+ 2,
+ )
+
@skipUnlessDBFeature("has_bulk_insert")
def test_bulk_insert_nullable_fields(self):
fk_to_auto_fields = {
}}}
crashes with:
{{{
django.db.utils.DatabaseError: ORA-01830: date format picture ends before
converting entire input string
}}}
As far as I'm aware we can use `LOCALTIMESTAMP` instead (which return
`TIMESTAMP`) because time zones are ignored on Oracle.
Noticed while checking
https://github.com/django/django/pull/16092#issuecomment-1264633158
--
Ticket URL: <https://code.djangoproject.com/ticket/34558>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018809c5cf6a-825b54a3-8d60-43ad-8540-d2bc43db0322-000000%40eu-central-1.amazonses.com.