[Product-Developers] IObjectAddedEvent fires 5 times instead of 1 time
Maarten Nieber
maarten at usecm.com
Thu Dec 22 17:03:32 UTC 2011
Hi,
I registered a handler for the IObjectAddedEvent, but it gets fired 5 times
instead of one (I have a set_trace in the event handler), one time when before
the add page for the new IHomePage instance is shown, and various times after
clicking Save.
Also, the second time I get the pdb (using set_trace), it seems there is some
kind of corruption, because when I request the value of self a few times, it
returns nothing, but then I request the value one more time, and it returns my
HomePage instance.
Any ideas? Also, why does the handler get called before saving the new instance?
Thanks
Maarten
I'm registering the handler like this (IHomePage is Archetypes based)
<subscriber
for="elmolino.backend.interfaces.IHomePage
zope.app.container.interfaces.IObjectAddedEvent"
handler="elmolino.backend.content.homepage.createHomePage" />
This is the handler
def create(self):
"""
Helper that finishes the construction by creating several member
variables (this code does not work when called from the constructor).
"""
import ipdb; ipdb.set_trace()
self.invokeFactory(
'Folder',
'admin',
title=_(u"Admin")
)
self.adminFolder = self['admin']
self.adminFolder.reindexObject()
self.adminFolder.invokeFactory(
'ShowsFolder',
'shows',
title=_(u"Shows")
)
self.shows = self.adminFolder['shows']
self.adminFolder.invokeFactory(
'Folder',
'artists',
title=_(u"Artists")
)
artistsFolder = self.adminFolder['artists']
artistsFolder.reindexObject()
artistsFolder.invokeFactory(
'ArtistsFolder',
'current_artists',
title=_(u"Current Artists")
)
self.currentArtists = artistsFolder['current_artists']
self.currentArtists.reindexObject()
artistsFolder.invokeFactory(
'ArtistsFolder',
'ens_han_visitat',
title=_(u"Ens han visitat")
)
self.currentArtistsEnsHanVisitat = artistsFolder['ens_han_visitat']
self.currentArtistsEnsHanVisitat.reindexObject()
artistsFolder.invokeFactory(
'ArtistsFolder',
'past_artists',
title=_(u"Past Artists")
)
self.pastArtists = artistsFolder['past_artists']
self.pastArtists.reindexObject()
self.reindexObject()
ps Also, at some point, this error shows up in the debugger console
2011-12-22 17:53:41 INFO ZPublisher.Conflict ConflictError at
/em/portal_factory/HomePage/homepage.2011-12-22.5472924060/kssValidateField:
database conflict error (oid 0x0161, class BTrees.IOBTree.IOBTree, serial this
txn started with 0x039343b47fa46055 2011-12-22 16:52:29.916116, serial currently
committed 0x039343b5ad5c9b11 2011-12-22 16:53:40.631658) (2 conflicts (0
unresolved) since startup at Thu Dec 22 17:48:43 2011)
More information about the Product-Developers
mailing list