[ZODB-Dev] strange savepoint behavior

dvd dvd at gnx.it
Thu Nov 3 11:32:04 EST 2005


On Thu, 2005-11-03 at 09:44 -0500, Tim Peters wrote:
> You didn't say which version of ZODB you're using, but I doubt it matters:
> I was able to reproduce the POSKeyError in the current ZODB 3.6 branch.

I'm using ZODB 3.5.1

> 
> I expect it's an artificial glitch due to never committing anything (i.e.,
> an extreme case some part of the code just isn't expecting).  If I add
> 
>     transaction.commit()
> 
> right after your
> 
>     data = root['data'] = OOBTree()
> 
> then the POSKeyError goes away, and I get
> 
>     Traceback (most recent call last):
>       File "pos_dvd.py", line 34, in ?
>         print commonWords[1].id
>     AttributeError: 'Word' object has no attribute 'id'
> 
> instead.  That makes sense to me:  rolling back invalidates the in-memory
> Word objects, and they lose all their user-defined attributes then.  Since
> the object states were never committed (except to savepoints that were
> explicitly thrown away), there's no way to get the attributes back.

great! this is exactly the error that i'm trying to reproduce
so is this an expected behavior (the lost of the attributes)?
this sounds a bit strange to me, let me explain:

with:
**** CODE ****
sv = transaction.savepoint()
for word in commonWords:
	sv2 = transaction.savepoint()
	data[word.id] = word
**************

the last line (print ....) raise an AttributeError:

with:
**** CODE ****
sv = transaction.savepoint()
for word in commonWords[0:1]:
	sv2 = transaction.savepoint()
	data[word.id] = word
**************

all works fine (no AttributeError)

obviously if i omit the second savepoint, all works fine

if rolling back invalidates the in-memory objects, why without the
second savepoint the "id" attribute still exists?

thank you
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/20051103/91931e63/attachment.bin


More information about the ZODB-Dev mailing list