#34558 closed Bug (fixed)

QuerySet.bulk_create() crashes with Now() on Oracle.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords: oracle
Cc: David Sanders, Lily Foote Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

  • tests/bulk_create/tests.py

    diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py
    index a5050c9b0b..aee0cd9996 100644
    a b from django.db import (  
    1010    connection,
    1111)
    1212from django.db.models import FileField, Value
    13 from django.db.models.functions import Lower
     13from django.db.models.functions import Lower, Now
    1414from django.test import (
    1515    TestCase,
    1616    override_settings,
    class BulkCreateTests(TestCase):  
    300300        bbb = Restaurant.objects.filter(name="betty's beetroot bar")
    301301        self.assertEqual(bbb.count(), 1)
    302302
     303    @skipUnlessDBFeature("has_bulk_insert")
     304    def test_bulk_insert_now(self):
     305        NullableFields.objects.bulk_create(
     306            [
     307                NullableFields(datetime_field=Now()),
     308                NullableFields(datetime_field=Now()),
     309            ]
     310        )
     311        self.assertEqual(
     312            NullableFields.objects.filter(datetime_field__isnull=False).count(),
     313            2,
     314        )
     315
    303316    @skipUnlessDBFeature("has_bulk_insert")
    304317    def test_bulk_insert_nullable_fields(self):
    305318        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

Change History (2)

comment:1 by David Sanders, 12 months ago

Triage Stage: UnreviewedAccepted

comment:2 by GitHub <noreply@…>, 12 months ago

Resolution: fixed
Status: assignedclosed

In 72a86ceb:

Fixed #34558 -- Fixed QuerySet.bulk_create() crash with Now() on Oracle.

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