Ticket #7226 (closed Bug: fixed)

Opened 7 years ago

Last modified 6 years ago

plone.app.contentmenu: Issue with non ISelectableBrowserDefault aware content

Reported by: ajung Owned by: deo
Priority: minor Milestone: 3.1
Component: General Version:
Keywords: Cc:

Description

With ZWiki 0.6.1 I get somethine the following error due to a None.Title() call within menu.py. I suggest to add an additional check and set the title to if the object is None. This issue also occurs sometimes with other older products. It is a workaround but it makes much more older products work properly within Plone 3.0

Time 2007/10/17 08:55:44.014 GMT+2 User Name (User Id) ajungtest (ajungtest) Request URL  http://www.plone4universities.org/wiki/index_html Exception Type AttributeError Exception Value 'NoneType' object has no attribute 'Title'

Traceback (innermost last):

  • Module ZPublisher.Publish, line 119, in publish
  • Module ZPublisher.mapply, line 88, in mapply
  • Module ZPublisher.Publish, line 42, in call_object
  • Module Products.ZWiki.ZWikiPage, line 258, in call
  • Module Products.ZWiki.ZWikiPage, line 271, in render
  • Module Products.ZWiki.pagetypes.rst, line 60, in render
  • Module Products.ZWiki.Views, line 711, in addSkinTo
  • Module Shared.DC.Scripts.Bindings, line 313, in call
  • Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
  • Module Products.CMFCore.FSPageTemplate, line 216, in _exec
  • Module Products.CMFCore.FSPageTemplate, line 155, in pt_render
  • Module Products.PageTemplates.PageTemplate, line 89, in pt_render
  • Module zope.pagetemplate.pagetemplate, line 117, in pt_render
  • Module zope.tal.talinterpreter, line 271, in call
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 891, in do_useMacro
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 536, in do_optTag_tal
  • Module zope.tal.talinterpreter, line 521, in do_optTag
  • Module zope.tal.talinterpreter, line 516, in no_tag
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 957, in do_defineSlot
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 536, in do_optTag_tal
  • Module zope.tal.talinterpreter, line 521, in do_optTag
  • Module zope.tal.talinterpreter, line 516, in no_tag
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 861, in do_defineMacro
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 534, in do_optTag_tal
  • Module zope.tal.talinterpreter, line 516, in no_tag
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 745, in do_insertStructure_tal
  • Module zope.tales.tales, line 696, in evaluate URL: main_template Line 103, Column 18 Expression: <StringExpr u'plone.contentviews'> Names:

{'container': <PloneSite at /p4u>,

'context': <ZWikiPage 'index_html' at 0x2aaaaaf96150>, 'default': <object object at 0x2b5f63e56200>, 'here': <ZWikiPage 'index_html' at 0x2aaaaaf96150>, 'loop': {}, 'nothing': None, 'options': {'args': (<ZWikiPage 'index_html' at 0x2aaaaaf96150>,

<HTTPRequest, URL= http://www.plone4universities.org/wiki/index_html>),

'body': '<h1 class="title">Plone4Universities Wiki</h1>\n<p>The purpose of this wiki is for collecting idea and resources before they make it into official pages.\n\n</p>\n<p class="commentheading"><strong>Wiki Frontpage</strong> --ajungtest, Wed, 17 Oct 2007 08:52:34 +0200 <a class="reference" href=" http://www.plone4universities.org/wiki/WikiPage200710178664642517?subject=Wiki%20Frontpage&amp;in_reply_to=%3C20071017085234%2B0200%40www.plone4universities.org%3E#bottom">reply</a></p>\n'},

'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x2b5f6d2c70e0>, 'request': <HTTPRequest, URL= http://www.plone4universities.org/wiki/index_html>, 'root': <Application at >, 'template': <FSPageTemplate at /p4u/wikipage used for /p4u/wiki/index_html>, 'traverse_subpath': [], 'user': <PloneUser 'ajungtest'>}

  • Module Products.Five.browser.providerexpression, line 37, in call
  • Module plone.app.viewletmanager.manager, line 140, in render
  • Module Shared.DC.Scripts.Bindings, line 313, in call
  • Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
  • Module Products.PageTemplates.PageTemplateFile, line 129, in _exec
  • Module Products.PageTemplates.PageTemplate, line 89, in pt_render
  • Module zope.pagetemplate.pagetemplate, line 117, in pt_render
  • Module zope.tal.talinterpreter, line 271, in call
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 855, in do_condition
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 536, in do_optTag_tal
  • Module zope.tal.talinterpreter, line 521, in do_optTag
  • Module zope.tal.talinterpreter, line 516, in no_tag
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 534, in do_optTag_tal
  • Module zope.tal.talinterpreter, line 516, in no_tag
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 745, in do_insertStructure_tal
  • Module zope.tales.tales, line 696, in evaluate URL: contentactions Line 31, Column 8 Expression: <StringExpr 'plone.contentmenu'> Names:

{'container': <ZWikiPage 'index_html' at 0x2aaaaaf96150>,

'context': <ZWikiPage 'index_html' at 0x2aaaaaf96150>, 'default': <object object at 0x2b5f63e56200>, 'here': <ZWikiPage 'index_html' at 0x2aaaaaf96150>, 'loop': {}, 'nothing': None, 'options': {'args': ()}, 'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x2aaaac962710>, 'request': <HTTPRequest, URL= http://www.plone4universities.org/wiki/index_html>, 'root': <Application at >, 'template': <ImplicitAcquirerWrapper object at 0x74ccfd0>, 'traverse_subpath': [], 'user': <PloneUser 'ajungtest'>, 'view': <Products.Five.viewlet.metaconfigure.ContentActionsViewlet object at 0x2aaaab3f4b50>, 'views': <zope.app.pagetemplate.viewpagetemplatefile.ViewMapper object at 0x74cc790>}

  • Module Products.Five.browser.providerexpression, line 37, in call
  • Module Shared.DC.Scripts.Bindings, line 313, in call
  • Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
  • Module Products.PageTemplates.PageTemplateFile, line 129, in _exec
  • Module Products.PageTemplates.PageTemplate, line 89, in pt_render
  • Module zope.pagetemplate.pagetemplate, line 117, in pt_render
  • Module zope.tal.talinterpreter, line 271, in call
  • Module zope.tal.talinterpreter, line 346, in interpret
  • Module zope.tal.talinterpreter, line 586, in do_setLocal_tal
  • Module zope.tales.tales, line 696, in evaluate URL: contentmenu Line 1, Column 0 Expression: <PathExpr standard:'view/menu'> Names:

{'container': <ZWikiPage 'index_html' at 0x2aaaaaf96150>,

'context': <ZWikiPage 'index_html' at 0x2aaaaaf96150>, 'default': <object object at 0x2b5f63e56200>, 'here': <ZWikiPage 'index_html' at 0x2aaaaaf96150>, 'loop': {}, 'nothing': None, 'options': {'args': ()}, 'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x2aaaab41b3f8>, 'request': <HTTPRequest, URL= http://www.plone4universities.org/wiki/index_html>, 'root': <Application at >, 'template': <ImplicitAcquirerWrapper object at 0x7a701d0>, 'traverse_subpath': [], 'user': <PloneUser 'ajungtest'>, 'view': <plone.app.contentmenu.view.ContentMenuProvider object at 0x7a70950>, 'views': <zope.app.pagetemplate.viewpagetemplatefile.ViewMapper object at 0x7a70790>}

  • Module zope.tales.expressions, line 217, in call
  • Module Products.PageTemplates.Expressions, line 161, in _eval
  • Module Products.PageTemplates.Expressions, line 123, in render
  • Module plone.app.contentmenu.view, line 41, in menu
  • Module zope.app.publisher.browser.menu, line 66, in getMenuItems
  • Module zope.app.publisher.browser.menu, line 176, in getMenu
  • Module plone.app.contentmenu.menu, line 286, in getMenuItems

AttributeError: 'NoneType' object has no attribute 'Title'

Display traceback as text

Change History

comment:1 Changed 6 years ago by limi

  • Component changed from Unknown to Infrastructure

Yup, agreed.

comment:2 follow-up: ↓ 4 Changed 6 years ago by raphael

I'd like to suggest a slightly different fix:

To the extend that I understand what's going on here the situation always comes up if the current context cannot be adapted to ISelectableBrowserDefault. While this always works for Plone's default types it doesn't always need to be the case for add-ons. In that case 'context = ISelectableBrowserDefault(obj, None)' may result in None.

To be somewhat more robust, use 'obj' right away if 'context' is None. E.g., like in (menu.py around line 290)

# Display the selected item (i.e. the context)

if context is None:

raw_title = obj.title_or_id()

else:

raw_title = context.Title()

results.append({ 'title' : _(u'label_item_selected',

default=u'Item: ${contentitem}', mapping={'contentitem' : _safe_unicode(raw_title)

}),

...

Not sure the adapted context is needed for this at all (I mean to display the title) so the above might be more complicated than needed but I didn't check ...

Raphael

comment:3 Changed 6 years ago by hannosch

  • Owner changed from somebody to optilude

comment:4 in reply to: ↑ 2 Changed 6 years ago by klm

Replying to raphael:

I'd like to suggest a slightly different fix:

To the extend that I understand what's going on here the situation always comes up if the current context cannot be adapted to ISelectableBrowserDefault.

i've noticed that it's only triggered when the page being visited is designated as the default view of the container.

While this always works for Plone's default types it doesn't always need to be the case for add-ons. In that case 'context = ISelectableBrowserDefault(obj, None)' may result in None.

whatever the reason, having context default to None if the object isn't adaptable to ISelectableBrowserDefault, but then referring later use context.Title(), is a mistake.

To be somewhat more robust, use 'obj' right away if 'context' is None. E.g., like in (menu.py around line 290)

# Display the selected item (i.e. the context)

if context is None:

raw_title = obj.title_or_id()

else:

raw_title = context.Title()

results.append({ 'title' : _(u'label_item_selected',

default=u'Item: ${contentitem}', mapping={'contentitem' : _safe_unicode(raw_title)

}),

this fix works for me. i'm also contending with ZWiki pages as default view for a folder, as andreas was, but the problem will occur for any object not adaptable to ISelectableBrowserDefault.

Not sure the adapted context is needed for this at all (I mean to display the title) so the above might be more complicated than needed but I didn't check ...

this is something i'm puzzled about.

my workaround was just to default to the parent if the adaptation isn't feasible - in menu.py, line 236, instead of:

        context = ISelectableBrowserDefault(obj, None)

use:

        context = ISelectableBrowserDefault(obj, parent)

the parent object is obtained for "isDefaultPage"s, just a few lines above the one i'm talking about.

this is a simpler, but more intrusive workaround than raphael's. i don't know what the actual fix would be, because i don't understand what context is for. but i am sure DisplayMenu.getMenuItems() is broken, as is, and preventing plone 3 operation with some third-party content types. i'm hoping some motion would happen on this soon.

Raphael

ken manheimer  http://myriadicity.net

comment:5 Changed 6 years ago by deo

  • Owner changed from optilude to deo
  • Status changed from new to assigned

As Ken said, the error is only triggered when the page being visited is designated as the default view of the container.

The problem, in this case, is that page is not ISelectableBrowserDefault-aware (eg: CMF or AT based content, except ATCT) and the error happens only when trying to get the page's Title to display it as the selected item in the display menu.

Raphael was not sure the adapted context is needed to get the page's Title. In fact his if/else check is not necessary and the patch can be resumed to only:

Index: plone/app/contentmenu/menu.py
===================================================================
--- plone/app/contentmenu/menu.py     (revisão 19636)
+++ plone/app/contentmenu/menu.py     (cópia de trabalho)
@@ -286,7 +286,7 @@
                                      'submenu'      : None,
                                      })
             # Display the selected item (i.e. the context)
-            results.append({ 'title'        : _(u'label_item_selected', default=u'Item: ${contentitem}', mapping={'contentitem' : _safe_unicode(context.Title())}),
+            results.append({ 'title'        : _(u'label_item_selected', default=u'Item: ${contentitem}', mapping={'contentitem' : _safe_unicode(obj.Title())}),
                              'description'  : '',
                              'action'       : None,
                              'selected'     : True,

I'll add a test to confirm this and then I'll close the issue.

comment:6 Changed 6 years ago by deo

  • Summary changed from plone.app.contentmenu: Issue with Zwiki to plone.app.contentmenu: Issue with non ISelectableBrowserDefault aware content

comment:7 follow-up: ↓ 8 Changed 6 years ago by deo

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [19638]) Fixed an issue with non ISelectableBrowserDefault aware content. This closes #7226.

comment:8 in reply to: ↑ 7 Changed 6 years ago by klm

Replying to deo:

(In [19638]) Fixed an issue with non ISelectableBrowserDefault aware content. This closes #7226.

i know this isn't an official part of the bug handling protocol, but: hooray! thanks. having this general issue finally settled is a relief.

comment:9 Changed 22 months ago by davisagli

  • Component changed from Infrastructure to General
Note: See TracTickets for help on using tickets.