Opened 4 years ago

Closed 4 years ago

#17056 closed Bug (fixed)

Creation of instances of a PK-only model fails under Oracle after introduction of bulk insert feature

Reported by: ramiro Owned by: ramiro
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


After r16739, trying to create an instance of this model:

from django.db import models

class Book(models.Model):


>>> from django.test import TestCase
>>> from models import Book
>>> Book.objects.create()

generates an error like this when run against Oracle:

Traceback (most recent call last):
  File "dtest/dtest01/store/", line 9, in test_insert
  File "django/upstream/django/db/models/", line 137, in create
    return self.get_query_set().create(**kwargs)
  File "django/upstream/django/db/models/", line 372, in create, using=self.db)
  File "django/upstream/django/db/models/", line 464, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "django/upstream/django/db/models/", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "django/upstream/django/db/models/", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "django/upstream/django/db/models/", line 1556, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "django/upstream/django/db/models/sql/", line 848, in execute_sql
    cursor.execute(sql, params)
  File "django/upstream/django/db/backends/oracle/", line 651, in execute
    query = convert_unicode(query % tuple(args), self.charset)
TypeError: not all arguments converted during string formatting

The compiler is generating the "DEFAULT" SQL keyword twice, once as part of the SQL query literal and once in the arguments tuple:

    ('DEFAULT', < object at 0x912c0ac>)

Currently, Django own test suite shows 80 errors of this type.

Change History (2)

comment:1 Changed 4 years ago by ramiro

  • Owner changed from nobody to ramiro
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

In [16997]:

Fixed #17056 -- Tweaked insert SQL clause generation so a corner case doesn't fail with Oracle.

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