Most Powerful Open Source ERP

Technical Note on Why _Aq_Dynamic Patch Is Required

showing why _aq_dynamic support in Zope is required by ERP5.
  • Last Update:2016-04-22
  • Version:001
  • Language:en

ERP5 requires an unofficial patch for _aq_dynamic support in Zope. The patch adds this functionality:

  • If an object does not have an attribute but has the method _aq_dynamic, _aq_dynamic is called in the context of the object when acquiring the attribute.
  • The method _aq_dynamic must return None if an attribute is not found, otherwise return an acquired value.
  • A call to _aq_dynamic happens before acquiring an attribute from the parent, and after trying to get the attribute from the object itself.

ERP5 uses _aq_dynamic to generate methods automatically, based on definitions in the file system, definitions in the portal, etc. For example, property accessors (such as getQuantity) are generated in this way. Because ERP5 supports TTW (Through the Web) development and customization, it is very important that _aq_dynamic is called with the information on a portal site, so that the user can set custom properties, categories, and so on on portal_types.

Table of Contents

Why standard ways do not work

There are some ways to implement a similar feature. http://zopewiki.org/Acquisition describes some ideas. But they are not sufficient for our purpose.

__bobo_traverse__

   Basically, this method is to tweak the traverse of an URL. This method is not used when getattr is used, for example.

__getattr__

   __getattr__ is a good candidate, because it is called only if an attribute is not found, and the semantics is quite similar to _aq_dynamic. However, __getattr__ is called with aq_base, that is, self is not an acquisitoin wrapper when called. So it is not possible to get information about a portal site.

__setstate__

   This method is called too early. It is even before acquisition wrapping.

__of__

   This method is called too early, too. Because this method is called when getting an object, the state of the object is not always fully integrated into a portal site.

Why the patch is not integrated into the upstream

Only because we don't get along with the developmental version of Zope yet. Currently, our focus is more on improving the stability of ERP5 with the current set of installations. Certainly, we should discuss how to make the patch go into the official version with Zope developers, once we are ready for moving to the latest version of Zope.

Is there any side effect by the patch?

If an object is not an acquisition wrapper, nothing changes.

If an object has an attribute in itself, nothing changes.

If an object does not have an attribute, and if the object does not have _aq_dynamic, only one attribute lookup is performed. The performance penalty is negligible.

If an object does not have an attribute, but has _aq_dynamic, this method is called. Since this method is called every time when getting the same attribute, as long as the object does not define the attribute, _aq_dynamic should set the attribute on the object or its class at the first call, and should avoid evaluating a complex expression at the second call and later.

Related Articles