[ZODB-Dev] Mutating class of an instance
Marius Gedminas
marius at gedmin.as
Thu Jul 3 12:09:04 EDT 2008
(Adding zodb-dev at zope.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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20080703/d59cc520/attachment.bin
More information about the ZODB-Dev
mailing list