[ZPT] Re: Not a METAL problem (was: BUG] something wrong with METAL (as bundled with Zope 2.5.1))

Dieter Maurer dieter@handshake.de
Thu, 8 Aug 2002 23:34:20 +0200


Dieter Maurer writes:
 > I reported:
 >  > The templates that define macros appear to be looked up hundreds/thousands
 >  > of times. As lookup is very expensive in Zope (due to acquisition),
 >  > this is a considerable performance stopper.
 > 
 > I know by now that it is not a METAL problem. All lookups, not only
 > METAL lookups, are repeated hundreds of times.
 > 
 > I will find out what causes these repetitions and let you know...
It has been my "__getattr__":

  I am working on CMF content where part of the attributes are in
  a relational database. My "__getattr__" looks something like:

    def __getattr(self,key):
      if self._v_fetched is None:
        self._v_fetched= some_ZSQL_method(...)[0]
      return getattr(self._v_fetched,key)

  Looks innocent, doesn't it?

  Nevertheless, it is severely flawed: the "getattr" above first
  looks "key" up in "_v_fetched" and than (due to acquisition) in
  "self", leading to recursion. This is finally broken, when
  the "maximum recursion depth" is exceeded. The corresponding
  exception is silently ignored.

  "getattr(aq_base(self._v_fetched),key)" solves my problem.


Sorry for the false alarm!


Dieter