[PEAK] wiki IntroToPeak / deleting lazy bindings

Doug Quale quale1 at charter.net
Thu Jun 17 13:39:56 EDT 2004


While working through Lesson Three of the IntroToPeak on the wiki
(http://peak.telecommunity.com/DevCenter/IntroToPeak_2fLessonThree?action=show)
I ran into something I'm not clear about.

The abortTransaction() method deletes an attribute that is created
with binding.Make():

    def abortTransaction(self, ob):
        del self.data
        super(MessageDM,self).abortTransaction(ob)

Using PEAK 0.53a, when I try this code out by forcing an abort by
making a change to command.py, it fails:

$ ./hello for Doug: test a rollback
Jun 17 10:52:04 shiva logger[30121]: <peak.storage.transactions.TransactionService object at 0x404ae30c>: error during participant abort
Jun 17 10:52:04 shiva logger[30121]: Traceback (most recent call last):
Jun 17 10:52:04 shiva logger[30121]:   File "/usr/local/lib/python2.3/site-packages/peak/storage/transactions.py", line 256, in abort
Jun 17 10:52:04 shiva logger[30121]:     p.abortTransaction(self)
Jun 17 10:52:04 shiva logger[30121]:   File "/home/quale/Projects/leo/intro/helloworld/storage.py", line 44, in abortTransaction
Jun 17 10:52:04 shiva logger[30121]:     del self.data
Jun 17 10:52:04 shiva logger[30121]:   File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 56, in _once.BaseDescriptor.__delete__
Jun 17 10:52:04 shiva logger[30121]: KeyError: 'data'

Is it supposed to be possible to delete an attribute bound using
binding.Make() before its value has been computed?  It would be a noop
in that case if it worked.  Changing the code to

    def abortTransaction(self, ob):
        self.data = None
        del self.data
        super(MessageDM,self).abortTransaction(ob)

makes it work.  Is that the correct idiom?



More information about the PEAK mailing list