﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7411	Saving db object while iterating over a queryset larger than ITER_CHUNK_SIZE breaks with sqlite	Jenan Wise	Malcolm Tredinnick	"== Example ==

=== simpleapp/models.py: === 
{{{
#!python
from django.db import models

class SimpleModel(models.Model):
    num = models.IntegerField()
}}}

=== bugtest.py: === 
{{{
#!python
from django.db.models import query
from simpleapp.models import SimpleModel

# fill the db
for i in range(query.ITER_CHUNK_SIZE + 1): 
    SimpleModel(num=i).save()

for item in SimpleModel.objects.all():
    item.save() # breaks on *first* iteration of loop
}}}

=== Traceback: === 
{{{
Traceback (most recent call last):
  File ""bugtest.py"", line 19, in <module>
    item.save() # breaks on *first* iteration of loop
  File ""/Library/Python/2.5/site-packages/django/db/models/base.py"", line 272, in save
    self.save_base()
  File ""/Library/Python/2.5/site-packages/django/db/models/base.py"", line 341, in save_base
    transaction.commit_unless_managed()
  File ""/Library/Python/2.5/site-packages/django/db/transaction.py"", line 140, in commit_unless_managed
    connection._commit()
  File ""/Library/Python/2.5/site-packages/django/db/backends/__init__.py"", line 20, in _commit
    return self.connection.commit()
sqlite3.OperationalError: SQL logic error or missing database
}}}

== Details ==
 * When using ''just'' django.db.models.query.ITER_CHUNK_SIZE objects or fewer, no exception is raised.
 * When forcing evaluation of the queryset, e.g. wrapping it in list(), no exception is raised.
 * It doesn't matter whether the item being saved is one from the queryset.  Any database save will break.

== Affected DBs ==
 * Both in-memory SQLite and SQLite using a file database have the same problem.
 * PostgreSQL is unaffected
 * MySQL untested
"		closed	Database layer (models, ORM)	dev		fixed	sqlite, queryset, iteration	uptimebox@…	Accepted	0	0	0	0	0	0
