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

Claudiu Saftoiu csaftoiu at gmail.com
Tue Jun 19 20:23:03 UTC 2012


On Tue, Jun 19, 2012 at 2:29 PM, Malthe Borch <mborch at gmail.com> wrote:

> On 19 June 2012 19:54, Claudiu Saftoiu <csaftoiu at gmail.com> 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 minor performance hit as it does the check
> each
> > time the object is loaded.
> >
> > Is there a way to do that last option? What's the best practice for this
> > sort of thing, in general?
>
> 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.
>

Thanks, I wasn't aware. Seems to work - much appreciated!

- Claudiu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/zodb-dev/attachments/20120619/a9b199c7/attachment-0001.html>


More information about the ZODB-Dev mailing list