[Zope] Can't use aq_parent in Product??

Florent Guillaume fg@nuxeo.com
12 Nov 2001 16:54:29 GMT


In __init__ you are in a pure python class constructor. The object
you're constructing has not yet been assigned its place in the Zope
tree, so it doesn't *have* a parent.

If you want to do post-constructor initializations, do them after the
object has been created and put in the tree via _setObject. See my other
recent post about this.

Florent



Paul Winkler  <slinkp23@yahoo.com> wrote:
> I have a Product I'm creating (python, not Zclass).  I thought that I
> could get the parent object of an instance of my product using the
> aq_parent method. But AFAIKT, this only works on an "acquisition
> wrapper" of an object - not on the object itself??
> 
> Example: try this in  Boring product:
> 
> class BrokenBoring(
>     OFS.SimpleItem.Item,   # A simple Principia object. Not Folderish. 
>     Persistent,            # Make us persistent. Yaah! 
>     Acquisition.Implicit,  # Be able to find things via acquisition.
>     AccessControl.Role.RoleManager # Security manager. 
>     ): 
>     """
>     Can't acquire the parent... fooey.
>     """        
>     meta_type = 'Boring' # what do people think they're adding? 
> 
> (snip)
> 
>     def __init__(self, id, title=''): 
>         """initialise a new instance of Boring"""
> 
> (snip)
>         try: assert hasattr(self, "aq_parent")
>         except: print "Hey! This instance can't acquire parent!!"
> 
> 
> When you add one of these in a folder, it prints the exception message
> in the log. In other words ... no aq_parent.
> 
> So I guess I need to get an acquisition wrapper to self, so I can
> acquire its parent? How do I do that? I can't figure it out from the
> DevGuide.  Or Is there a less bletcherous solution?
> Help!
> 
> --
> 
> paul winkler
> home:  http://www.slinkp.com
> music: http://www.reacharms.com
> calendars: http://www.calendargalaxy.com
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> 


-- 
Florent Guillaume, Nuxeo SARL (Paris, France)
+33 1 40 33 79 10  http://nuxeo.com  mailto:fg@nuxeo.com