Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-20 Thread Stefan H. Holek
One thing I seem to remember is that changes made in __setstate__ do not mark the object as dirty. This is because after being loaded an object is up-to-date by definition. I suggest going with zope.generations. Stefan On 19.06.2012, at 23:42, Malthe Borch wrote: > On 19 June 2012 23:38, Cl

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Malthe Borch
On 19 June 2012 23:38, Claudiu Saftoiu wrote: > Is there any hook to call *after* the instance attributes get set/loaded > from the database? True. I guess you'll have to go with Marius' suggestion – ``__setstate__``. \malthe ___ For more information a

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Claudiu Saftoiu
> > You'll need to override ``__new__``. That's your hook. It's called > when the database instantiates the object. Note that this is always > true for Python. The ``__new__`` method is always called before an > object is instantiated. > Actually, this doesn't seem to be what I want. ``__new__`` i

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Marius Gedminas
On Tue, Jun 19, 2012 at 10:15:03PM +0200, Vincent Pelletier wrote: > Le mardi 19 juin 2012 19:54:21, Claudiu Saftoiu a écrit : > > def calc_it(self, b): > > if not hasattr(self, 'b_cache'): self.b_cache = > > PersistentDict() > > If you were to use this, you would probably pref

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Claudiu Saftoiu
On Tue, Jun 19, 2012 at 2:29 PM, Malthe Borch wrote: > On 19 June 2012 19:54, Claudiu Saftoiu wrote: > > That is, a function called whenever the object is loaded, that does all > the > > necessary backwards-compatibility > > work right there. It separates the backwards-compat code cleanly, and >

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Vincent Pelletier
Le mardi 19 juin 2012 20:50:55, Marius Gedminas a écrit : > Yes, you can override __setstate__: [...] > It's also best to avoid write-on-read semantics, because those tend to > cause database growth and increase the chances of getting ConflictErrors. This is also a problem with __setstate__, and I

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Vincent Pelletier
Le mardi 19 juin 2012 19:54:21, Claudiu Saftoiu a écrit : > def calc_it(self, b): > if not hasattr(self, 'b_cache'): self.b_cache = > PersistentDict() If you were to use this, you would probably prefer to do try: self.b_cache except AttributeError: self.

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Marius Gedminas
On Tue, Jun 19, 2012 at 01:54:21PM -0400, Claudiu Saftoiu wrote: > Ideally I could do something like this: > > class Foo(Persistent): > def __init__(self, a): > self.a = a > self.b_cache = PersistentDict() > > def __just_loaded__(self): > if

Re: [ZODB-Dev] Is any function called when an object is loaded from the database?

2012-06-19 Thread Malthe Borch
On 19 June 2012 19:54, Claudiu Saftoiu wrote: > That is, a function called whenever the object is loaded, that does all the > necessary backwards-compatibility > work right there. It separates the backwards-compat code cleanly, and also > only updates the objects > as-needed... though still a mino