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

Malthe Borch mborch at gmail.com
Tue Jun 19 18:29:47 UTC 2012


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.

\malthe


More information about the ZODB-Dev mailing list