[ZODB-Dev] Re: copy.copy on Persistent object (ExtensionClass) fails.

Dieter Maurer dieter at handshake.de
Fri May 7 14:21:46 EDT 2004


Casey Duncan wrote at 2004-5-6 16:12 -0400:
>On Thu, 6 May 2004 21:08:11 +0200
>Dieter Maurer <dieter at handshake.de> wrote:
> ...
>> 	copy = loads(dumps(obj,1))
>> 
>> Be warned, however, that this uses undocumented implementation
>> details of "dumps" that are not garanteed to always work
>> and may change across Python distributions.
>
>Can you elaborate on that?

Something causes "obj" (and its descendants) to be loaded into
memory. I expect that this happens because "dumps" checks
for some attribute.
When the class does not define such an attribute, the object is
loaded from ZODB.
Suppose, all attributes "dumps" looks for are defined by
the object's class, then the object might not be loaded
and an empty instance could be pickled.

I could be wrong, though, and "Persistent.__getstate__"
might force the object to be loaded. In this case,
copying through pickling might be safe.
But, I did not investigate....

-- 
Dieter



More information about the ZODB-Dev mailing list