IPublishTraverse that is part of a view not being invoked

Bug #143765 reported by Martin Aspeli
4
Affects Status Importance Assigned to Milestone
Zope 2
Fix Released
Medium
Unassigned

Bug Description

I believe (but I'm unable to write a test now) that if a view implements IPublishTraverse, its publishTraverse() method is never called.

To check, try to edit adding.py in Five and put a pdb or print statement in publishTraverse(). Go to /foo/bar/+/foobar - if I understand things correctly, this should invoke publishTraverse(name='foobar'), but in my tests it does not.

Revision history for this message
Philipp von Weitershausen (philikon) wrote :

I think what Martin means is that given a URL path like a/b/c with the 'b' object providing IPublishTraverse, the ZPublisher will still look up an IPublishTraverse multi-adapter and not take advantage of b already providing the IPublishTraverse API. 'b' can also be a view, but in general, it can be any object.

Revision history for this message
Lennart Regebro (regebro-gmail) wrote :

No, the ZPublisher will check if the object provides IPublishTraverse and use it directly. I tested this with a
view and it works fine.

Revision history for this message
Lennart Regebro (regebro-gmail) wrote :

Changes: submitter email, edited transcript

Revision history for this message
Martin Aspeli (optilude) wrote :

So, would you say Five/browser/adding.py is an example of something that ought to work? I can't get its publishTraverse() to invoke if I e.g. do

http://localhost:8080/site/folder/+/foobar

putting a pdb in publishTraverse() should cause a debugger session and give me name='foobar', should it not? It didn't for me :-/

Martin

Revision history for this message
Bertrand Mathieu (bmat) wrote :

Got it with zope 2.10.5. The culprit is Five metaconfigure.I have made a patch with tests, but the error seems obvious: just compare Products/Five/browser/metaconfigure.py and zope/app/publisher/browser/viewmeta.py. The code in Five seems to be an old copy/paste.

In short: the view class is wrapped by Five. If it has a 'publishTraverse' method it should be called by the wrapper. But the code get the method with: class_.publishTraverse.__get__(self).__of__(self) => __of__ on a method?! The code in zope.app is the same without __of__
I guess there is a try/except somewhere that hides this error.

The patch is made against svn://svn.zope.org/repos/main/Products.Five/branches/1.5 at rev80401.

Revision history for this message
Philipp von Weitershausen (philikon) wrote : Re: [Bug 143765] Re: IPublishTraverse that is part of a view not being invoked

On 18 Apr 2008, at 14:11 , Bertrand Mathieu wrote:
> Got it with zope 2.10.5. The culprit is Five metaconfigure.I have
> made a
> patch with tests, but the error seems obvious: just compare
> Products/Five/browser/metaconfigure.py and
> zope/app/publisher/browser/viewmeta.py. The code in Five seems to be
> an
> old copy/paste.
>
> In short: the view class is wrapped by Five. If it has a
> 'publishTraverse' method it should be called by the wrapper. But the
> code get the method with:
> class_.publishTraverse.__get__(self).__of__(self) => __of__ on a
> method?! The code in zope.app is the same without __of__
> I guess there is a try/except somewhere that hides this error.

This code is indeed strange. Your observations seem to be correct.
However, it would be good to see how you tested this...

> The patch is made against
> svn://svn.zope.org/repos/main/Products.Five/branches/1.5 at rev80401.

Thanks for the patch. It seems to be missing the 'view.txt' file,
though, which contains the test. This is the interesting bit :).

Revision history for this message
Bertrand Mathieu (bmat) wrote :

oh too bad. Sorry! I quickly made a svn diff, but forgot svn add view.txt... I'll see if I can rewrite view.txt, I've lost it :-/.

Basically I don't know how to call the publish traverse process, so for my test I get the view instance from the test content, and call directly view.publishTraverse('traversed') on it; because the actual bug is that Five "publishTraverse wrapper" fails at finally calling the method, I think it is correct.

Revision history for this message
Philipp von Weitershausen (philikon) wrote :

On 18 Apr 2008, at 14:42 , Bertrand Mathieu wrote:
> oh too bad. Sorry! I quickly made a svn diff, but forgot svn add
> view.txt... I'll see if I can rewrite view.txt, I've lost it :-/.

Argh, why would you delete it? Anyway, perhaps it's enough just to add
another paragraph/section to an existing test?

> Basically I don't know how to call the publish traverse process, so
> for
> my test I get the view instance from the test content, and call
> directly
> view.publishTraverse('traversed') on it; because the actual bug is
> that
> Five "publishTraverse wrapper" fails at finally calling the method, I
> think it is correct.

Please look at the other tests (e.g. pages.txt, pages_ftest.txt)!

Revision history for this message
Jens Vagelpohl (dataflake-deactivatedaccount-deactivatedaccount) wrote :

The supposed bad wrapping using "__of__" disappeared shortly after this bug was filed, closing as resolved:

http://svn.zope.org/?rev=85767&view=rev

Changed in zope2:
assignee: nobody → Jens Vagelpohl (dataflake)
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.