[ZODB-Dev] misleading exception
dvd
dvd at gnx.it
Fri Nov 4 11:49:19 EST 2005
Hi all,
I'm still working with savepoints and today I spend about tewo hours to
find an error, misleaded by a strange Exception
ZODB: 3.5.1
<code>
from ZODB import FileStorage, DB
from BTrees.OOBTree import OOBTree
import transaction
def CreateDatabase(fname, creds):
uid, password = creds
try: os.unlink(fname)
except Exception: pass
try: os.unlink(fname + '.index')
except Exception: pass
try: os.unlink(fname + '.tmp')
except Exception: pass
fstorage = FileStorage.FileStorage(fname)
db = DB(fstorage)
try:
conn = db.open()
try:
try:
root = conn.root()
root['users'] = OOBTree()
root['files'] = OOBTree()
root['collections'] = OOBTree()
root['relation'] = None
transaction.get().commit()
root['users'][uid] = password
transaction.get().commit()
except Exception, e:
print "Exception occurs",e
raise
finally:
transaction.get().abort()
conn.close()
finally:
db.close()
fstorage.close()
print "First Step"
CreateDatabase("/tmp/ciao.fs", ('foo', 'bar'))
fstorage = FileStorage.FileStorage("/tmp/ciao.fs")
db = DB(fstorage)
conn = db.open()
root = conn.root()
sv = transaction.savepoint()
root['files'][1] = 1
sv.rollback()
#transaction.get().abort()
conn.close()
db.close()
fstorage.close()
# be sure the database is no longer here
import os
os.unlink("/tmp/ciao.fs")
print "Second Step"
CreateDatabase("/tmp/ciao.fs", ('foo', 'bar'))
</code>
If I run the code above I obtain an obscure (for me) traceback:
Traceback (most recent call last):
File "pp.py", line 62, in ?
CreateDatabase("/tmp/ciao.fs", ('foo', 'bar'))
File "pp.py", line 27, in CreateDatabase
transaction.get().commit()
File "/usr/lib/python2.3/site-packages/transaction/_transaction.py",
line 389, in commit
self._saveCommitishError() # This raises!
File "/usr/lib/python2.3/site-packages/transaction/_transaction.py",
line 387, in commit
self._commitResources()
File "/usr/lib/python2.3/site-packages/transaction/_transaction.py",
line 430, in _commitResources
rm.tpc_begin(self)
File "/usr/lib/python2.3/site-packages/ZODB/Connection.py", line 468,
in tpc_begin
self._normal_storage.tpc_begin(transaction)
File "/usr/lib/python2.3/site-packages/ZODB/BaseStorage.py", line 214,
in tpc_begin
self._clear_temp()
File
"/usr/lib/python2.3/site-packages/ZODB/FileStorage/FileStorage.py", line
851, in _clear_temp
self._tfile.seek(0)
ValueError: I/O operation on closed file
If I decomment the following line
#transaction.get().abort()
all works fine.
The strange is that the exception is raised when i try to commit the
transaction in the second call of CreateDatabase
If i omit the savepoint rollback *and* the abort line I obtain a
meaningful error:
ZODB.POSException.ConnectionStateError: Cannot close a connection joined
to a transaction
Maybe this report can help someone
bye
david
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20051104/13e542a7/attachment.bin
More information about the ZODB-Dev
mailing list