[Grok-dev] Unwanted macro caching in page templates: problem found

Reinout van Rees reinout at vanrees.org
Wed Apr 8 04:09:42 EDT 2009

Hi all,

With a lot of print statements, I found the reason for
https://bugs.launchpad.net/grok/+bug/162261. The problem: normally if you
change a page template while in debug mode, you get the new page when
refreshing in your browser. This also used to work for templates with macros
in them: refreshing a page that uses a changed template's macros would get you
the new macros. Not anymore since somewhere late 2007.

I found the problem: grokcore/view/components.py, around line 213. In the
PageTemplate class::

    def _initFactory(self, factory):
        factory.macros = self._template.macros

That ought to be something like::

    def _initFactory(self, factory):
        def _get_macros(self):
            return self.template._template.macros
        factory.macros = property(_get_macros)

Reason: self_template.macros is a property in zope pagetemplate that does a
_cook_check() and returns self._v_macros. With the existing code, the macros
property of zope pagetemplate is called just once and subsequent cook checks
don't happen.

With the new code, the original macros() call, including cook check, is
getting called all the time.

The special macros attribute setting by _initFactory is, according to
jwkolman, especially for zope page templates. So this changes seems warranted.

I'll prepare a patch (with test) for this. Does anyone see a problem with this


Reinout van Rees - reinout at vanrees.org - http://reinout.vanrees.org
Software developer at http://www.thehealthagency.com
"Military engineers build missiles. Civil engineers build targets"

More information about the Grok-dev mailing list