[BlueBream] Copied objects losing support for __parent__ and getParents

Michael Howitz mh at gocept.com
Mon Oct 18 02:41:17 EDT 2010


Am 17.10.2010 um 19:01 schrieb Jonah Crawford:
> After copying some container objects using zope.copy.clone the objects that have been copied as well as those which have been copied into are no longer supporting calls involving __parent__ and getParents . I manually set each copied objects new parent like so:
> 
>         source_obj_name = str(source_obj.__name__)[:]
>         newobj = zope.copy.clone(source_obj)
>         newobj.__name__ = source_obj_name
>         newobj.__parent__ = target_obj
> 
> but this doesn't seem to solve the issue. Any thoughts as to what I'm not doing ?

You only create a clone of the object, which has no context any more. Put it into a container so it gets the context for ``getParents``.

Besides this, I use the following code to clone an object:


        unsecure_source = zope.security.proxy.getObject(source_obj)
        copier = zope.copypastemove.interfaces.IObjectCopier(unsecure_source)
        new_name = copier.copyTo(new_parent)

Where ``new_parent`` is a zope.container. Removing the security proxy might not be necessary.



Yours sincerely,
-- 
Michael Howitz · mh at gocept.com · software developer
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 8 · fax +49 345 1229889 1
Zope and Plone consulting and development



More information about the bluebream mailing list