Code

Opened 3 years ago

Closed 3 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

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.

Attachments (0)

Change History (2)

comment:1 Changed 3 years ago by ramiro

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

comment:2 Changed 3 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.