[Zope] manage_pasteObjects in manage_afterAdd raises AttributeError for getPhysicalRoot

Grégoire Weber gregoire.weber@switzerland.org
Wed, 25 Sep 2002 02:01:19 +0200


Hi Dieter,
Hi All,

AttributeError / getPhysicalRoot has gone changing 

   index_obj = getattr(container.aq_base, 'index_html', None)

to

   if hasattr(container.aq_base, 'index_html'):
      index_obj = getattr(container, 'index_html')
   else:
      index_obj = None

I thought they were equivalent -- they're not !!!

Can somebody confirm that (inclusive reasons)?

Gruss, Gregoire

-----------------------------------------------------------------------
<CODE working="correct">
def manage_afterAdd(self, item, container):
   """ simplified code called after instanation of object A 
       (self) in folder P (container)
   """
   if hasattr(container.aq_base, 'index_html'):
      index_obj = getattr(container, 'index_html')
      if index_obj.meta_type == self.meta_type:
          # P has an object I (index_obj) of the same type as A is
          index_obj.addToCollection(container, self.getId())

def addToCollection(self, container, id):
   """ simplified code in the same class called on index_html object 
   """
  # this copies object A (container/id, just instanated before 
   # manage_afterAdd!!!) to object I (self, same as index_obj above)
   cb = container.manage_copyObjects(id) # OK
   self.manage_pasteObjects(cb) # raises ERROR (same as before)
</CODE>

At 22:16 24.09.2002 +0200, Dieter Maurer wrote:
>=?iso-8859-1?Q?Gr=E9goire?= Weber writes:
> > ...
> > def addToCollection(self, obj):
> > ...
> >    self.manage_pasteObjects(context.manage_copyObjects(id)) # raises=
 ERROR below
> >=
 -------------------------------------------------------------------------
> > Error Type: AttributeError
> > Error Value: getPhysicalRoot
> > 
> > Traceback (innermost last):
> >   File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in=
 manage_pasteObjects
> >     (Object: index_html)
> > AttributeError: (see above)
>This means, "self" above, does not have a method "getPhysicalRoot".
>
>This may be because it is only partially acquisiton wrapped.
>
>   Usually, you should check for attribute existence with "aq_base"
>   but access without the "aq_base".
>
>   I.e., you should use the following idiom:
>
>   if hasattr(aq_base(obj),'some_attribute'):
>      my_attribute= getattr(obj,'some_attribute')
>      ...
>
>
>Dieter 

_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org