[Kss-devel] "Could not adapt" error with event subscribers firing during an ajax call
Hedley Roos
hedley at upfrontsystems.co.za
Thu Nov 8 14:55:45 CET 2007
David Bain gives a complete explanation at
http://lists.plone.org/pipermail/product-developers/2007-October/000882.html
This is a straight copy-and-paste from that page. My comments below...
----- snippet ---
I have some code that creates a simple folder.
It seems that when invokeFactory is called via a "kss wrapper", the result
is a 'could not adapt' error.
Maybe I'm misinterpreting this, anyone familiar with this issue? Would love
your assistance.
I've included traceback and snippets of the original code, I figure that
should help.
Note:
- that when the method is called directly or via a non-kss based
method it works fine.
- When called wrapped in a kss based method I get a 'could not adapt'
error.
the traceback when called from my KSS based method:
2007-10-23 07:46:06 ERROR Zope.SiteErrorLog
http://localhost:8081/Plone/poleroll/my-roll/kss_do_stuff/do_stuff
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 <wrapper>, line 5, in wrapper
Module kss.core.actionwrapper, line 238, in apply
Module Products.peopleroll.browser.dostuff, line 12, in do_stuff
Module Products.peopleroll.content.organization, line 276, in
do_the_stuff
Module Products.CMFCore.PortalFolder, line 315, in invokeFactory
Module Products.CMFCore.TypesTool, line 716, in constructContent
Module Products.CMFCore.TypesTool, line 276, in constructInstance
Module Products.CMFCore.TypesTool, line 450, in _constructInstance
Module Products.ATContentTypes.content.folder, line 7, in addATFolder
Module OFS.ObjectManager, line 348, in _setObject
Module zope.app.container.contained, line 365, in notifyContainerModified
Module zope.event, line 23, in notify
Module zope.component.event, line 26, in dispatch
Module zope.component._api, line 130, in subscribers
Module zope.component.registry, line 290, in subscribers
Module zope.interface.adapter, line 535, in subscribers
Module kss.core.kssview, line 127, in _eventRedispatcher
Module zope.component._api, line 130, in subscribers
Module zope.component.registry, line 290, in subscribers
Module zope.interface.adapter, line 535, in subscribers
Module plone.app.kss.globalui, line 23, in
attributesTriggerDocumentBylineReload
Module kss.core.kssview, line 169, in getCommandSet
TypeError: ('Could not adapt', <Products.Five.metaclass.DoTheStuff object at
0x6ca7470>, <InterfaceClass plone.app.kss.commands.interfaces.IZopeCommands
>)
The Original Method from a content type called an organization:
----snip---
security.declarePublic('do_the_stuff')
def do_the_stuff(self,results, **kwargs):
"""
do stuff here
"""
dtnow = DateTime()
year = str(DateTime.year(dtnow))
if year not in self.contentIds():
self.invokeFactory(id=year,title=year,type_name="Folder")
----snip---
The KSS class:
from kss.core import KSSView, kssaction
from Acquisition import aq_inner
from datetime import datetime
class DoTheStuff(KSSView):
@kssaction
def do_stuff(self, widgetid='blah', href='yah.com'):
ksscore = self.getCommandSet('core')
selector = ksscore.getHtmlIdSelector('organization-results')
do_it = self.context.do_the_stuff
output = do_it()
ksscore.replaceInnerHTML(selector,
'<h1>%s</h1>' % output)
-------------- next part --------------
----- snippet ---
I have the exact same error when trying to call
portal_membership.addMember during an ajax call.
It seems that an event subscriber notifyContainerModified branches off
into some code that updates the document byline via ajax.
From globalui.py we have
@component.adapter(None, IKSSView, IObjectModifiedEvent)
def attributesTriggerDocumentBylineReload(obj, view, event):
ksscore = view.getCommandSet('core')
selector = ksscore.getHtmlIdSelector('plone-document-byline')
zopecommands = view.getCommandSet('zope')
zopecommands.refreshViewlet(selector,
'plone.belowcontenttitle',
'plone.belowcontenttitle.documentbyline')
From kssview.py we have
def getCommandSet(self, name):
commandset = getRegisteredCommandSet(name)
# return the adapted view
return commandset.provides(self)
getCommandSet successfully retrieves the core commandset, but the "could
not adapt" error happens when trying to retrieve the zope commandset.
At first I thought that the calling context must be wrong (the
commandset.provides(self) bit), but how can that be? self is surely a view?
So, bit stuck here. David Bain also received no replies. Anyone else
have this issue?
Hedley
More information about the Kss-devel
mailing list