[Persistence-sig] A simple Observation API

Niki Spahiev niki@vintech.bg
Wed, 31 Jul 2002 11:29:41 +0300


Phillip J. Eby wrote:
>>def addDate(self, date):
>>   self.dates.append(date)  # self.dates is a simple list
>>   self.dates.sort()
>>   self._p_changed = 1
>>
>>Let's say self.dates.sort() raises some exception that leads to an aborted
>>transaction.  Objects are supposed to be reverted on transaction abort,
>>but that won't happen here!  The connection was never notified that there
>>were changes, so self.dates is now out of sync.  But if the application
>>sets _p_changed just *before* the change, aborting will work.
> 
> 
> Good point.  I hadn't really thought about that use case.  But the
> Observation API I proposed does support it, via separate
> beforeChange()/afterChange() notifications.  A DM could track
> beforeChange() to know that an object needs rolling back, and
> afterChange(), to actually send a change through to an underlying DB, if
> it's in write-through mode at the time.

Maybe this will solve it?

def addDate(self, date):
    self._p_changed = 1
    self.dates.append(date)  # self.dates is a simple list
    self.dates.sort()
    self._p_changed = 1

_p_changed before *and* after?

regards,
Niki Spahiev