zope.traversing.interfaces.ITraversable violation #59

Open
dokai opened this Issue Sep 20, 2011 · 3 comments

4 participants

@dokai

The ITraversable interface defines the the traverse method's furtherPath parameter as "a list of names still to be traversed. This method is allowed to change the contents of furtherPath."

However, when used in Plone 4.1 the furtherPath parameter is a tuple instead of a list which makes it impossible for the ITraversable implementation to modify it.

I noticed this when writing a view template for a Dexterity type that uses path traversal to render an image tag by traversing to a plone.namedfile image (e.g. @@images/image/thumb). The ITraversable implementation in plone.namedfile.scaling.ImageScaling attempts to .pop() the furtherPath which fails because it is a tuple.

Components used: Chameleon 2.4.4, z3c.pt 2.1.4, five.pt 2.1.5, Plone 4.1, plone.namedfile 1.0.4

@do3cc

Heya,
I encountered the same problem, but the issues are within z3c.pt and five.pt
1. in z3c.pt.expressions.PathExpr template is called with an ast.Tuple object. When changing the Tuple to a List, the old exception gets changed. The furtherPath Element is not a tuple any longer, but a list, and namedfile can pop the list.
2. The next problem occurs because five.pt.expressions.BoboAwareZopeTraverse.traverse. It does not pass a the same list to the Traverser object, but a copy. As dokai mentioned, the api explicitly states that the traverse method is allowed to change the contents of furtherPath. This more or less implies, that the traverse method should not get a copy of the list, but the real thing. namedfile mangles the furtherPath to remove some elements from it. Because BoboAwareZopeTraverse gave him a copy of the path elements lists, BoboAwareZopeTraverse continues to consume path elements, but this will not yield any object, but another exception.

While I could get everything working with some changes, even commit the changes, I'd prefer to if somebody would review any changes.

@maciekz

Hi,

I'm affraid the issue is still there. I've run into it while using five.pt-2.2.1 with Plone 4.2.6 and plone.app.imaging-1.0.9. plone.app.imaging expects to get a list as furtherPath but it gets a tuple instead.

I didn't dig into it much, but when using this in ZPT template:

<img tal:replace="structure context/@@images/photo/picture" />

I'm getting a traceback:

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 Products.Five.browser.metaconfigure, line 479, 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 five.pt.engine, line 93, in __call__
  Module z3c.pt.pagetemplate, line 149, in render
  Module chameleon.zpt.template, line 258, in render
  Module chameleon.template, line 170, in render
  Module cf7d80a3d7e13f915d66774c46785648, line 1885, in render
  Module cf7d80a3d7e13f915d66774c46785648, line 1189, in render_master
  Module five.pt.expressions, line 161, in __call__
  Module Products.Five.browser.metaconfigure, line 479, 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 five.pt.engine, line 93, in __call__
  Module z3c.pt.pagetemplate, line 149, in render
  Module chameleon.zpt.template, line 258, in render
  Module chameleon.template, line 188, in render
  Module chameleon.template, line 170, in render
  Module 7cba5a9dadce209dd4a2895fe36132d6, line 317, in render
  Module five.pt.expressions, line 154, in __call__
  Module five.pt.expressions, line 126, in traverse
  Module zope.traversing.adapters, line 136, in traversePathElement
   - __traceback_info__: (<Products.Five.metaclass.ImageScaling object at 0x7f2870a46f90>, 'photo')
  Module plone.app.imaging.scaling, line 80, in traverse
AttributeError: 'tuple' object has no attribute 'pop'

I'm happy to provide some more info or to do some debugging when pointed in the right direction.

Regards,
MaciekZ

@malthe
Owner

Good question. I would need to look closer at this to know what's the solution. I don't really have a Plone stack handy though hmmm ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment