[Zope] Re: a question about aq_base

Max M maxm at mxm.dk
Wed Nov 29 06:53:00 EST 2006


Dieter Maurer skrev:
> Yuri wrote at 2006-11-28 14:23 +0100:
>> here: http://docs.neuroinf.de/programming-plone/ate we can read:
>>
>>        obj = brain.getObject().aq_base
>>
>> why .aq_base and not only brain.getObject()? :)
> 
> Usually, it is a bad idea to use "aq_base" in Zope applications
> 
> You should carefully examine the context of the code fragment above.
> Maybe, the context is one of the rare situations where "aq_base"
> is called for...

Why is it rare?

I often need to check if an object has a certain attribute. Getting 
aquisition into the mix is a bad idea there.::

     name = getattr(obj, 'name')

Is a lot different than

     name = getattr(obj.aq_base, 'name')

In the first example you don't know if the name attribute is an aquired 
object or an attribute on the actual object. Which can make for 
uncontrollable results.

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science



More information about the Zope mailing list