[Django] #22705: can't bulk create models with no fields

36 views
Skip to first unread message

Django

unread,
May 26, 2014, 12:06:04 PM5/26/14
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-----------------------------------+--------------------
Reporter: ellery-newcomer@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
I have a model


{{{
class Discussion(models.Model): pass
}}}


I try to do this:


{{{
discussions = [Discussion() for i in range(n)]
Discussion.objects.bulk_create(discussions)
}}}

it fails with

AttributeError: 'NoneType' object has no attribute 'column'

because

django.db.models.sql.compiler.SQLInsertCompiler.as_sql has the following
line in it:


{{{
fields = [None]
}}}


which doesn't get tripped on models that have fields, apparently.

--
Ticket URL: <https://code.djangoproject.com/ticket/22705>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 28, 2014, 7:49:24 PM5/28/14
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Can reproduce with the attached test for Django's test suite.

--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:1>

Django

unread,
Mar 28, 2015, 11:11:35 PM3/28/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: assigned

Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by chrisjluc):

* owner: nobody => chrisjluc
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:2>

Django

unread,
Apr 5, 2015, 7:25:55 PM4/5/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: assigned
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by chrisjluc):

I've modified the compiler to create the below query, but I'm getting an
Integrity Error: datatype mismatch when I run it in Django. I assume it's
because `id` is a pk and it doesn't accept `NULL` values, but it seems to
work on my own sqlite. Does anyone know how to solve this issue?

We use the second form of bulk inserting, ref
https://www.sqlite.org/lang_insert.html

`u'INSERT INTO "bulk_create_nofields" ("id") SELECT %s UNION ALL SELECT %s
UNION ALL SELECT %s', (u'NULL', u'NULL', u'NULL'))`

{{{
Traceback (most recent call last):
File
"/Users/chrisjluc/Documents/opensource/django/tests/bulk_create/tests.py",
line 172, in test_empty_model
NoFields.objects.bulk_create(objs)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/manager.py",
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/query.py",
line 445, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/query.py",
line 1043, in _batched_insert
using=self.db)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/manager.py",
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/query.py",
line 1026, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/models/sql/compiler.py",
line 974, in execute_sql
cursor.execute(sql, params)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/chrisjluc/Documents/opensource/django/django/db/utils.py",
line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File
"/Users/chrisjluc/Documents/opensource/django/django/db/backends/sqlite3/base.py",
line 318, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: datatype mismatch
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:3>

Django

unread,
Aug 6, 2015, 1:09:34 PM8/6/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: assigned
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
QuerySet.bulk_create |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* keywords: => QuerySet.bulk_create


--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:4>

Django

unread,
Oct 8, 2015, 9:21:14 PM10/8/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: assigned
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
QuerySet.bulk_create |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


Comment:

Fixed in Django 1.9 by 134ca4d438bd7cbe8f0f287a00d545f96fa04a01.

[https://github.com/django/django/pull/5415 PR] to add a regression test.

--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:5>

Django

unread,
Oct 8, 2015, 10:38:17 PM10/8/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: assigned
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
QuerySet.bulk_create | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


Comment:

Regression test LGTM.

--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:6>

Django

unread,
Oct 9, 2015, 2:42:34 PM10/9/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: closed

Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
QuerySet.bulk_create | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"7a5b7e35bf2e219225b9f26d3dd3e34f26e83e9c" 7a5b7e35]:
{{{
#!CommitTicketReference repository=""
revision="7a5b7e35bf2e219225b9f26d3dd3e34f26e83e9c"
Fixed #22705 -- Fixed QuerySet.bulk_create() on models without any fields
on Oracle.

Fixed on other backends by 134ca4d438bd7cbe8f0f287a00d545f96fa04a01.

Thanks Mariusz Felisiak for the solution.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:7>

Django

unread,
Oct 9, 2015, 2:42:48 PM10/9/15
to django-...@googlegroups.com
#22705: can't bulk create models with no fields
-------------------------------------+-------------------------------------
Reporter: ellery-newcomer@… | Owner: chrisjluc
Type: Bug | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
QuerySet.bulk_create | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7cd299584dd9b152c736854c6558670e57512d40" 7cd2995]:
{{{
#!CommitTicketReference repository=""
revision="7cd299584dd9b152c736854c6558670e57512d40"
[1.9.x] Fixed #22705 -- Fixed QuerySet.bulk_create() on models without any
fields on Oracle.

Fixed on other backends by 134ca4d438bd7cbe8f0f287a00d545f96fa04a01.

Thanks Mariusz Felisiak for the solution.

Backport of 7a5b7e35bf2e219225b9f26d3dd3e34f26e83e9c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22705#comment:8>

Reply all
Reply to author
Forward
0 new messages