Example
simpleapp/models.py:
from django.db import models
class SimpleModel(models.Model):
num = models.IntegerField()
bugtest.py:
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