[Django] #34558: QuerySet.bulk_create() crashes with Now() on Oracle.

8 views
Skip to first unread message

Django

unread,
May 11, 2023, 3:45:42 AM5/11/23
to django-...@googlegroups.com
#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.

Django

unread,
May 11, 2023, 5:31:21 AM5/11/23
to django-...@googlegroups.com
#34558: QuerySet.bulk_create() crashes with Now() on Oracle.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz

| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34558#comment:1>

Django

unread,
May 11, 2023, 12:23:45 PM5/11/23
to django-...@googlegroups.com
#34558: QuerySet.bulk_create() crashes with Now() on Oracle.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed

Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: oracle | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"72a86ceb33749d4fd17d3d2910e19b9d9ca1643b" 72a86ceb]:
{{{
#!CommitTicketReference repository=""
revision="72a86ceb33749d4fd17d3d2910e19b9d9ca1643b"
Fixed #34558 -- Fixed QuerySet.bulk_create() crash with Now() on Oracle.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34558#comment:2>

Reply all
Reply to author
Forward
0 new messages