Re: [ZODB-Dev] Mutating class of an instance
by Marius Gedminas other posts by this author
Jul 3 2008 9:09AM messages near this date
Re: [ZODB-Dev] Mutating class of an instance
|
Re: [ZODB-Dev] Mutating class of an instance
(Adding zodb-dev@[...].org back to Cc:)
On Thu, Jul 03, 2008 at 09:14:27AM -0400, Erik Dahl wrote:
> On Jul 2, 2008, at 10:55 AM, Marius Gedminas wrote:
>
> >>
> >>inst.__class__ = NewClass
> >
> >Is inst a persistent object? Then your only chance to get this to
> >work
> >is to find *all* objects that reference inst and mark them _p_changed.
>
> Yes inst is a persistent object. Hum ok I will give this a try.
>
> >
> >>The class is also stored in every reference to that object.
>
> Well that something new to me... how come? Seems like they only need
> the oid.
My guess is that's for performance reasons. When you load the state of
an object X with an attribute 'y' referring to object Y, you end up with
two objects in memory: X with all of its state, and Y which is a "ghost"
(it only knows its own class and oid). To create the ghost you need to
know its class. To avoid loading the pickle of Y when you only need X,
every reference to Y stores both its oid and its class.
If you look at ZODB/serialize.py and look at ObjectWriter.persistent_id,
you'll see it stores references to persistent objects as (oid, class)
tuples.
Marius Gedminas
--
> find /lib/modules/2.4.17-expt/kernel/ -type f|while read i; do insmod $i; done
You're sick. I like you.
-- Andrew Morton on lkml
Thread:
Erik Dahl
Jim Fulton
Erik Dahl
Erik Dahl
Marius Gedminas
Marius Gedminas
Jim Fulton
Shane Hathaway
Andreas Jung
Jean Jordaan
|