Sunday, June 2, 2013

Fixing a broken view on a Dexterity based product after upgrading to Plone 4.3

TL;DR: I totally missed that the new Dexterity now ships with less dependencies. For me this meant that one of my products that depends on five.grok stopped working after the upgrade. The solution to the lack of the five.grok dependency in Dexterity was documented but not obviously enough for me so I'll repeat it here (skip to the last section of this post for details).


In order to identify what was broken I turned to the 'error_log' utility of the Zope Management Interface.

My little "trick" for enabling exceptions which are normally ignored by Plone is by adding a 'z' to the end of the exception name so that it gets logged and not skipped.

The 'error_log' was able to report that the view (even though it was working up to Plone 4.2) was now raising a "Not Found" exception on my Plone 4.3 based site. The view in this case called '@@sermons' was somehow no longer properly registered.

Diagnosing the source

My view was registered using a package called 'five.grok' which uses convention over configuration to associate views with a package. Here's a snippet of code that registers a simple view (5 to 7 lines of code):
from five import grok
from Products.ATContentTypes.interface import IATFolder
class Sermons(grok.View):
    """A BrowserView to display a Sermon listing on a Folder."""
    grok.context(IATFolder)  # type of object on which this View is available
    grok.require('zope2.View')  # what permission is needed for access

By convention because the class is called 'Sermons' it would be accessible via the name '@@sermons' or simply 'sermons' and would depend on a template called '' in the same directory (not shown here). The bottom line is that this all used to work.

The solution

Reintroduce the dependency in my buildout configuration and rerun buildout. This meant explicitly declaring the grok dependency. I also declared an additional dependency on a package called 'relations' just in case I had other code that needed that, then I reran buildout. The actual line that changed in order to do this explicit declaration involved adding a line like the one below in the appropriate eggs section of my buildout configuration:

eggs = [grok, relations]

Phew! my view worked after that.

No comments:

Sign up for my upcoming Plone 5 Book & Video tutorials

plone 5 for newbies book and videos