[TransWarp] __getitem__ on DM requires active transaction

Phillip J. Eby pje at telecommunity.com
Mon Dec 23 12:33:34 EST 2002


At 06:59 PM 12/23/02 +0200, Roché Compaan wrote:
>Hi Philip
>
>I had a look at the data_managers.py code in the storage package and
>something puzzles me.
>
>In the __getitem__ method of a QueryDM there is a call to
>self.joinedTxn.  This method will raise an exception if one is not
>already in a transaction (line 151 in transactions.py):
>
>         elif not self.isActive():
>             raise exceptions.OutsideTransaction
>
>What if I want to retrieve an object from a DataManager and I am not in
>a transaction? Surely one doesn't have to be in a transaction if you
>simply want to retrieve an object?

In your DM subclass, set:

resetStatesAfterTxn = False

If you want to be able to use your DM outside a 
transaction.  'resetStatesAfterTxn' means that you want your cache flushed 
between transactions so that data is guaranteed to be up-to-date in the 
current transaction.  In order to ensure that the data will be cleared, the 
DM must register with the transaction, and so it must do this when you read 
something.

Note that if you set this flag to False, then your cache will keep data 
more or less permanently, and at present there is no way to guarantee 
re-synchronization with your outside data source.  Until 'peak.storage' has 
a lock management API to let you request more up-to-date versions of an 
object or verify its current version, I would suggest you use DM's only 
inside of transactions, unless the DM is essentially read-only and you 
don't care if the data is out of date.




More information about the PEAK mailing list