Re: Bugtracker for z3c.relationfield and reasons for objects loosing their parent pointers
Patrick Gerken <[email protected]>
| Newsgroups | gmane.comp.web.zope.devel |
|---|---|
| Message-ID | <CAFefbnET65z-kfGsYSmEKCZUix2002NNLwd351LHCfg+FBkDBQ@mail.gmail.com> |
On Tue, Mar 27, 2012 at 15:18, Hanno Schlichting <[email protected]> wrote: > On Tue, Mar 27, 2012 at 2:53 PM, Patrick Gerken <[email protected]> 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. https://dev.plone.org/ticket/12802 Best regards, Patrick _______________________________________________ Zope-Dev maillist - [email protected] https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )