[ZODB-Dev] ZEO and setting instance variables in __getstate__

Syver Enstad syver at inout.no
Thu Dec 29 08:53:01 EST 2005


I have recently upgraded from ZODB 3.2 to 3.5.1. After doing this I 
notice that ZEO throws exceptions on commiting a transaction for certain 
types of Persistent classes.

Here is the traceback.

   File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", 
line 389, in commit
     self._saveCommitishError() # This raises!
   File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", 
line 387, in commit
     self._commitResources()
   File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", 
line 440, in _commitResources
     rm.tpc_finish(self)
   File "/usr/lib/python2.4/site-packages/ZODB/Connection.py", line 679, 
in tpc_finish
     self._storage.tpc_finish(transaction, callback)
   File "/usr/lib/python2.4/site-packages/ZEO/ClientStorage.py", line 
974, in tpc_finish
     self._update_cache(tid)
   File "/usr/lib/python2.4/site-packages/ZEO/ClientStorage.py", line 
999, in _update_cache
     self._cache.invalidate(oid, version, tid)
   File "/usr/lib/python2.4/site-packages/ZEO/cache.py", line 367, in 
invalidate
     assert tid is not None and cur_tid < tid
AssertionError

I narrowed it down to the problem occuring when I set instance variables 
in __getstate__ (called on commit) on a newly created persistent instance.

This only happens when I am using ZEO (ClientStorage) and not when using 
ZODB (FileStorage).

The reason I have chosen to override __getstate__ is to update the 
Persistent instance with the current username (which I store on the 
transaction when I open the connection) and a timestamp so that the 
instance knows when it was modified last and which user did it.

The new beforeCommitHook seems to be suited for this kind of work, but 
it doesn't give access to the changed objects in the transaction.


More information about the ZODB-Dev mailing list