Opened 13 years ago

Closed 13 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 Morales Owned by: Ramiro Morales
Component: Database layer (models, ORM) Version: dev
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

Description

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

from django.db import models

class Book(models.Model):
    pass

with:

>>> 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/tests.py", line 9, in test_insert
    Book.objects.create()
  File "django/upstream/django/db/models/manager.py", line 137, in create
    return self.get_query_set().create(**kwargs)
  File "django/upstream/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "django/upstream/django/db/models/base.py", line 464, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "django/upstream/django/db/models/base.py", 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/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "django/upstream/django/db/models/query.py", line 1556, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "django/upstream/django/db/models/sql/compiler.py", line 848, in execute_sql
    cursor.execute(sql, params)
  File "django/upstream/django/db/backends/oracle/base.py", 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:

[
  (
    'INSERT INTO "STORE_BOOK" ("ID") VALUES (DEFAULT) RETURNING "STORE_BOOK"."ID" INTO %s',
    ('DEFAULT', <django.db.backends.oracle.base.InsertIdVar object at 0x912c0ac>)
  )
]

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

Change History (2)

comment:1 by Ramiro Morales, 13 years ago

Owner: changed from nobody to Ramiro Morales
Triage Stage: UnreviewedAccepted

comment:2 by Ramiro Morales, 13 years ago

Resolution: fixed
Status: newclosed

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