On Tue, Mar 27, 2012 at 15:18, Hanno Schlichting <ha...@hannosch.eu> wrote:
> On Tue, Mar 27, 2012 at 2:53 PM, Patrick Gerken <do3cc...@googlemail.com> 
> wrote:
>> I found out, somewhat surprised, that __parent__ pointers are just
>> disguised aq_parent pointers.
> Are you maybe trying to use or set __parent__ on Acquisition wrappers
> instead of unwrapped objects?

Yes this is what happened with z3c.relationfields

> AQ wrappers have various attributes, among those aq_parent and
> __parent__ being the same thing. If you store an actual __parent__
> attribute on a "real" object, you should make sure to not wrap it in
> an Acquisition context or explicitly unwrap it before we
> Acquisition.aq_base(obj). You might need some compatibility code for
> "Zope 3" libraries, to introduce aq_base calls in the right places.

Hmm, since I didn't understand what magic happens with __parent__ pointers,
I tried the following in pdb:
>>> unwrapped = aq_base(a)
>>> unwrapped.__parent__ = aq_base(a.__parent__)

So I stored a not acquisition wrapped object onto the __parent__ attr
of another unwrapped object.
But then the result, unwrapped.__parent__ was acquisition wrapped again!
a and b both are subclasses of zope.container.contained.Contained,
which has some C Code for __parent__ pointer handling. How it works I
did not fully understand.

My conclusion on this is, that I can't use z3c.relationfield relations
directly in Zope2/Plone, but I need a tiny wrapper.
z3c.relationfield stores a normal acquisition wrapped object in an
attribute of a persistent relation. And after rollbacks or restarts
the __parent__ pointers are gone.


Best regards,

Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists -
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to