Opened 18 months ago
Closed 18 months ago
#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 ( 10 10 connection, 11 11 ) 12 12 from django.db.models import FileField, Value 13 from django.db.models.functions import Lower 13 from django.db.models.functions import Lower, Now 14 14 from django.test import ( 15 15 TestCase, 16 16 override_settings, … … class BulkCreateTests(TestCase): 300 300 bbb = Restaurant.objects.filter(name="betty's beetroot bar") 301 301 self.assertEqual(bbb.count(), 1) 302 302 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 303 316 @skipUnlessDBFeature("has_bulk_insert") 304 317 def test_bulk_insert_nullable_fields(self): 305 318 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 , 18 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 18 months ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
In 72a86ceb: