[Product-Developers] Re: plone.app.layout ViewletBase and portal_url

Raphael Ritz r.ritz at biologie.hu-berlin.de
Fri Mar 7 11:54:07 UTC 2008

Wichert Akkerman wrote:
> I'm debugging some code that broke in a very unexpected way:
> (Pdb) p getToolByName(self, 'portal_url')
> 'http://localhost:8080/Plone'
> That should return a tool, not a string. This turned out to be caused by 
> plone.app.layout.viewlets.common.ViewletBase.update which sets 
> self.portal_url to the portal URL. This looks harmless, but due to 
> acquisition this will break patterns like this:
> class MyViewlet(ViewletBase):
>    def update(self):
>       super(MyViewlet, self).update()
>       self.mt=getToolByName(self.context, "portal_membership")
>       self.somemethod()
>    def somemethod(self):
>       return self.mt.ToolMethod()
> the problem here is that in somemethod() self.mt gets acquisition wrapped in 
> the viewlet, so when ToolMethod does getToolByName(self, "portal_url") it
> finds the portal_url variable ViewletBase.update set on the viewlet instead
> of the tool.


(how long did it take you to track this down? Quite a while I
could imagine)

> I would like to rename that variable in ViewletBase to prevent this problem 
> but I do not have a good overview of how many people are relying on that 
> specific variable to be set. If you are relying on this please let me know 
> ASAP. If I here no objection I intend to rename the variable for the 
> upcoming Plone 3.1 alpha release.

+1 on renaming the variable.


> Wichert.

More information about the Product-Developers mailing list