Re: persistence and __setstate__
[email protected] (Barry A. Warsaw) Wed, 31 Jul 2002 11:53:43 -0400
| Newsgroups | gmane.comp.python.zope.zodb4 |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "JH" == Jeremy Hylton <[email protected]> writes: JH> A potential concern for any solution: If the object is updated JH> on demand, it is probably important to execute the change as a JH> separate transaction. If you don't, then the object update JH> gets mixed in with arbitrary updates to other objects, which JH> unnecessarily complicates undo. BAW> That's a good point, and sounds like the first approach might BAW> work better. Would the __setstate__ itself be able to do a BAW> transaction commit if it updated the object? If so, that BAW> might be enough, if inefficient for updating a large number BAW> of objects. Hmm. JH> How can you tell if __setstate__ updated the object? It JH> always updates the object :-(. Actually, I meant if __setstate__() updated the object's schema. Maybe I should have said "upgrade" instead of "update". __setstate__() should always know if this was the case or not, e.g.: def __setstate__(self, d): # ... upgraded = 0 if not d.has_key('newattr1'): self.newattr1 = 'blah' upgraded = 1 if not d.has_key('newattr2'): self.newattr2 = 'fleh' upgraded = 1 if upgraded: somehow_commit_a_transaction_with_the_new_object_state() -Barry