RESPONSE gone when using plone.memoize on tiles

this week we've been busy trying to solve a nasty performance issue on one of our sites; we already have the code located the solution has not been trivial:

we have a tile that display a link to the latest article of a list of authors; to get that piece of content I have to do a catalog search for each of the items in the list and this is killing the site.

our first idea was to implement results caching by using memoize, but every single way we have tested, we were getting a weird TypeError: 'NotImplementedType' object is not callable.

yesterday I dig into this issue and submitted a patch to avoid hiding exception raised inside the index() method:

and then I was able to see the real error that looks like this:

2017-03-17 00:31:49 ERROR Zope.SiteErrorLog 1489725109.470.443901532445
Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.tiles.esi, line 74, in __call__
  Module Products.Five.browser.pagetemplatefile, line 125, in __call__
  Module Products.Five.browser.pagetemplatefile, line 59, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module, line 98, in __call__
  Module, line 149, in render
  Module chameleon.zpt.template, line 261, in render
  Module chameleon.template, line 171, in render
  Module e2e8a8cb0ccaf124ca997cd3d42a8e5e, line 496, in render
  Module, line 161, in __call__
  Module Products.CMFDynamicViewFTI.browserdefault, line 70, in __call__
  Module plone.autoform.view, line 47, in __call__
  Module plone.directives.dexterity.form, line 181, in render
  Module five.grok.components, line 130, in render
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module, line 98, in __call__
  Module, line 149, in render
  Module chameleon.zpt.template, line 261, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module 46e71108af01ed762ca53797950e78d8, line 765, in render
  Module f3ec90ed7a03091afd2017dd1f335f47, line 925, in render_master
  Module AccessControl.ImplPython, line 675, in guarded_getattr
  Module ZPublisher.HTTPRequest, line 1391, in __getattr__
AttributeError: RESPONSE

 - Expression: "article"
 - Filename:   ... skins/example/portal/tiles/templates/
 - Location:   (line 44: col 23)
 - Source:     condition="article">
 - Expression: "python:request.RESPONSE.setHeader('X-UA-Compatible', 'IE=edge,chrome=1')"
 - Filename:   ... theme/sunburst/skins/sunburst_templates/
 - Location:   (line 16: col 3)
 - Source:     dummy python:request.RESPONSE.setHeader('X-UA-Compatible', 'IE=edge,chro ...
 - Arguments:  repeat: {...} (0)
               template: <ViewPageTemplateFile - at 0x7fe81a29ec90>
               views: <ViewMapper - at 0x7fe8085517d0>
               modules: <instance - at 0x7fe82aaefb00>
               args: <tuple - at 0x7fe831d73050>
               here: <ImplicitAcquisitionWrapper trump-na-contramao-do-mundo at 0x7fe80854ff00>
               static: <NoneType - at 0x8fe4d0>
               user: <ImplicitAcquisitionWrapper - at 0x7fe808573910>
               nothing: <NoneType - at 0x8fe4d0>
               translate: <function translate at 0x7fe80a77d410>
               container: <ImplicitAcquisitionWrapper trump-na-contramao-do-mundo at 0x7fe80854ff00>
               request: <instance - at 0x7fe80b236f38>
               wrapped_repeat: <SafeMapping - at 0x7fe80a7a5e10>
               traverse_subpath: <list - at 0x7fe813647128>
               default: <object - at 0x7fe831c8e520>
               context: <ImplicitAcquisitionWrapper trump-na-contramao-do-mundo at 0x7fe80854ff00>
               view: <Alternate_View alternate_view at 0x7fe8085d1dd0>
               target_language: pt_BR
               root: <ImplicitAcquisitionWrapper Zope at 0x7fe80b166fa0>
               options: {...} (0)
               loop: {...} (0)

I've being trying to add the memoizing in different ways: on a tile method, on a external utility function, and on a external helper view function (using memoize.view and ram.cache decorators) and all of them give the same problem.

any hint?

Yes (at random):

  • try with a lowercase response
  • do not use the main_template in your tile
  • consider loading the tile as a normal browser view through an ajax call (subrequests and performance hardly play well together)
  • if you use debug your page template with <?python locals().update(econtext); import ipdb; ipdb.set_trace() ?>

thanks! the tile was not using the main_template but then I discovered that I has missing the @implementer() declaration and tiles inheriting from ESIPersistentTile must implement IESIRendered.

also, looking at the error I changed the condition to:

condition="python:article is not None"

I think one of those things was the problem because it's working fine now.

1 Like

Any chance you could post / link to the code somewhere, since I have done a lot of work with tiles lately, and have experienced a lot of weird issues.


Saving tiles sometimes just 'spins' (cancel and edit again works)

Tiles 'swallow some html ( like <hr /> and <br />.

plone.outputfilters can not resolve uuidToURL  (maybe  using plone.api to get catalog could be an idea for everything that can be used by tiles ? )

I think you should wait for a new version of plone.tiles that do not swallow AttributeError (or to patch your local egg).

also, it's easier for you to share your code instead, as what I've done has nothing to do with what you have.

@espenmn plone.tiles 2.0.0b2 does not swallow AttributeError anymore.