On Tue, Jun 19, 2012 at 04:22:43PM -0400, Claudiu Saftoiu wrote: > Hello all, > > Say I have a: > > class Foo(Persistent): > def __init__(self, bar): > self.my_dict = PersistentDict({'keyis': bar}) > def update_it(self, bar): > self.my_dict['keyis'] = bar > > If I want to use a `dict`, instead (it seems it might be faster for my > larger example),
I doubt that. (OTOH if you have a large number of keys, consider using OOBTree instead of PersistentDict.) > how would I cause a change to the dict to > be committed? Is there any way other than this? > > class Foo(Persistent): > def __init__(self, bar): > self.my_dict = {'keyis': bar} > def update_it(self, bar): > self.my_dict['keyis'] = bar > self.my_dict = dict(self.my_dict) Yes: either def update_it(self, bar): self.my_dict['keyis'] = bar self.my_dict = self.my_dict or def update_it(self, bar): self.my_dict['keyis'] = bar self._p_changed = True I recommend against this pattern in general: it's too easy to forget the _p_changed bit and end up with bugs that are hard to notice. Because ZODB caches object instances, nonpersistent subobject modifications live on in memory until those objects get flushed (or Zope gets restarted), so you only notice you've a bug in your code when changes start mysteriously disappearing a few days after they're made. Marius Gedminas -- The Feynman Problem Solving Algorithm: 1) Write down the problem. 2) Think very hard. 3) Write down the solution.
signature.asc
Description: Digital signature
_______________________________________________ For more information about ZODB, see http://zodb.org/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev