Opened 16 years ago

Closed 16 years ago

#7636 closed (duplicate)

Transaction logic with sqlite3 and seems to be broken.

Reported by: lakin Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here is an example from the python manage.py shell:

In [1]: from django.db import transaction

In [2]: from flemish_eye.models import FileCode

In [3]: for fc in FileCode.objects.all():
   ...:     fc.save()
   ...: 
---------------------------------------------------------------------------
<class 'sqlite3.OperationalError'>        Traceback (most recent call last)

/home/lakin/Projects/flemish_eye/trunk/flemish_eye/<ipython console> in <module>()

/home/lakin/Projects/django/trunk/django/db/models/base.py in save(self)
    275         control the saving process.
    276         """
--> 277         self.save_base()
    278 
    279     save.alters_data = True

/home/lakin/Projects/django/trunk/django/db/models/base.py in save_base(self, raw, cls)
    344             if update_pk:
    345                 setattr(self, meta.pk.attname, result)
--> 346         transaction.commit_unless_managed()
    347 
    348         if signal:

/home/lakin/Projects/django/trunk/django/db/transaction.py in commit_unless_managed()
    138     """
    139     if not is_managed():
--> 140         connection._commit()
    141     else:
    142         set_dirty()

/home/lakin/Projects/django/trunk/django/db/backends/__init__.py in _commit(self)
     18     def _commit(self):
     19         if self.connection is not None:
---> 20             return self.connection.commit()
     21 
     22     def _rollback(self):

<class 'sqlite3.OperationalError'>: SQL logic error or missing database

In [4]: @transaction.commit_manually
   ...: def doit():
   ...:     transaction.commit()
   ...:     try:
   ...:         for fc in FileCode.objects.all():
   ...:             fc.save()
   ...:     finally:
   ...:         transaction.commit()
   ...: 

In [5]: doit()

In [6]: 

Although if I put similar code in a view or in a def save on a model, I get the same effect. :/

Attachments (1)

testbed.tar.bz2 (9.8 KB ) - added by lakin.wecker@… 16 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by lakin.wecker@…, 16 years ago

Here is some code that (when run with the about to be uploaded django project) will reproduce the error:

In [1]: from testbed.tester.models import FileCode

In [2]: from testbed.tester.models import FileCode, File

In [3]: file = File.objects.create(path='foo')

In [4]: for x in range(500):
   ...:     fc = FileCode.objects.create(file=file, code='code%d'%x)
   ...: 

In [5]: for fc in FileCode.objects.all():
   ...:     fc.save()
   ...: 
---------------------------------------------------------------------------
<class 'sqlite3.OperationalError'>        Traceback (most recent call last)

/home/lakin/Desktop/<ipython console> in <module>()

/home/lakin/Projects/django/trunk/django/db/models/base.py in save(self)
    275         control the saving process.
    276         """
--> 277         self.save_base()
    278 
    279     save.alters_data = True

/home/lakin/Projects/django/trunk/django/db/models/base.py in save_base(self, raw, cls)
    344             if update_pk:
    345                 setattr(self, meta.pk.attname, result)
--> 346         transaction.commit_unless_managed()
    347 
    348         if signal:

/home/lakin/Projects/django/trunk/django/db/transaction.py in commit_unless_managed()
    138     """
    139     if not is_managed():
--> 140         connection._commit()
    141     else:
    142         set_dirty()

/home/lakin/Projects/django/trunk/django/db/backends/__init__.py in _commit(self)
     18     def _commit(self):
     19         if self.connection is not None:
---> 20             return self.connection.commit()
     21 
     22     def _rollback(self):

<class 'sqlite3.OperationalError'>: SQL logic error or missing database

In [6]: 

by lakin.wecker@…, 16 years ago

Attachment: testbed.tar.bz2 added

comment:2 by lakin.wecker@…, 16 years ago

django trunk currently at (r7838).

Ubuntu 8.04, Python 2.5, and sqlite3.

comment:3 by Ramiro Morales, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #7411.

Note: See TracTickets for help on using tickets.
Back to Top