Event on object deletion

13 messages Options
Embed this post
Permalink
motion () Event on object deletion
Reply Threaded More More options
Print post
Permalink
Hi everybody,

in my project, I create objects with Archetypes and additionally I have to store and delete these objects in an other system.
On object creation I can use a subscription adapter like the example in Aspeli`s book
<subscriber 
        provides="Products.Archetypes.interfaces.IObjectPostValidation"
        factory=".cinema.ValidateCinemaCodeUniqueness" 
/>

to store them in the other system.

On object deletion I need to delete also the object in the other system, but I can`t find an event interface, that is called on deletion.
I tried to use
 
OFS.interfaces.IObjectWillBeRemovedEvent

 and
zope.app.container.interfaces.IObjectRemovedEvent
, but they are not called.

Does anyone know how if there is an interface, that is called on deletion or has another idea how to execute some code on object deletion?

Thank you very much for your help :)
Derek Broughton-3 () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
motion wrote:

> Does anyone know how if there is an interface, that is called on deletion
> or has another idea how to execute some code on object deletion?
>
zope.lifecycleevent.interfaces.IObjectModified is used with the "new" object
as None, iirc.
--
derek


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Martin Aspeli () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
In reply to this post by motion
motion wrote:

> Hi everybody,
>
> in my project, I create objects with Archetypes and additionally I have to
> store and delete these objects in an other system.
> On object creation I can use a subscription adapter like the example in
> Aspeli`s book
> <subscriber
>         provides="Products.Archetypes.interfaces.IObjectPostValidation"
>         factory=".cinema.ValidateCinemaCodeUniqueness"
> />
> to store them in the other system.

This is not a good event to use. You should use the
IObjectInitializedEvent from Archetypes. See chapter 9, on events.

> On object deletion I need to delete also the object in the other system, but
> I can`t find an event interface, that is called on deletion.
> I tried to use
>  OFS.interfaces.IObjectWillBeRemovedEvent
>  and
> zope.app.container.interfaces.IObjectRemovedEvent, but they are not called.

Mmm.... they should be called, unless your deletion takes place using
something other than _delObject() (the standard OFS API which Plone will
call).

You may, however, find that with linkintegrity installed, they're called
twice. Once for the LI checks which results in an aborted transaction,
and then again when you confirm the delete transaction. You need to be
resilient to this and either check for the LI marker on the request, or
make sure your external data store is transactional and hooks into the
Zope transaction manager.

> Does anyone know how if there is an interface, that is called on deletion or
> has another idea how to execute some code on object deletion?

IObjectRemovedEvent is definitely called when an object is deleted.

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
motion () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
ok, thank you for your response.

I managed to register two subscribers for creation and deletion of Myobject:
<subscriber
    	for="..interfaces.IObjectInterface 
    			Products.Archetypes.interfaces.IObjectInitializedEvent"
        handler=".myobject.storeMyObject" />
 <subscriber
    	for="..interfaces.IObjectInterface 
    			zope.app.container.interfaces.IObjectRemovedEvent"
    	handler=".myobject.deleteMyObject"
 />


My problem is, that I need to store and delete entities of Myobject in a background system via webservice, and if something goes wrong on creation and deletion, I
have to deal with this error, so that I don`t have local entities, that are not congruent with the background system.

Is there a way to throw an exception or something like this, to deal with these erros?
Or any other suggestions to realize this?

This is my first plone project and I am not that experienced with plone and zope, so excuse my questions :)
Martin Aspeli () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
motion wrote:

> ok, thank you for your response.
>
> I managed to register two subscribers for creation and deletion of Myobject:
> <subscriber
>     for="..interfaces.IObjectInterface
>     Products.Archetypes.interfaces.IObjectInitializedEvent"
>         handler=".myobject.storeMyObject" />
>  <subscriber
>     for="..interfaces.IObjectInterface
>     zope.app.container.interfaces.IObjectRemovedEvent"
>     handler=".myobject.deleteMyObject"
>  />
>
> My problem is, that I need to store and delete entities of Myobject in a
> background system via webservice, and if something goes wrong on creation
> and deletion, I
> have to deal with this error, so that I don`t have local entities, that are
> not congruent with the background system.

Well, the IObjectInitializedEvent won't get fired unless the edit
succeeded, IObjectRemovedEvent won't be fired unless the object is being
deleted. Note that with LinkIntegrity enabled, you may get the 'delete'
event twice: once when the link integrity check takes place, and again
when the transaction is confirmed. You'll need to handle that somehow,
or turn off linkintegrity.

That said, the only way to be properly transactional is to register a
transaction manager with Zope and use that to synchronise commit or
rollback in your external system.

You can look at a transaction manager for SQLAlchemy here:

http://svn.zope.org/zope.sqlalchemy/trunk/src/zope/sqlalchemy/

Note that this isn't entirely trivial, so if you can live with some risk
of transactions getting out of sync, the simple event handler approach
is a lot easier.

Martin


--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
motion () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
ok, writing an own transaction manager is too much for my business case, so
I think I will live with the risk of getting out of sync and find a workaround to deal with the situation, if both systems are not congruent.

Martin, you mentioned, that I have to "... check for the LI marker on the request ...".
How do I do this check?

thank you for your efforts ....




motion () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
On deletion, the method I registered as a subscriber is called three times.

Martin mentioned, that I can check for a marker interface to recognize if the event is called from LinkIntegrity or another part of plone.

I registered a subsriber for
Products.Archetypes.interfaces.IObjectInitializedEvent
 and for
zope.app.container.interfaces.IObjectRemovedEvent

The method signature for the notified delete-method is:
@adapter(IMyObject, IObjectRemovedEvent)
def deleteMyObject(self, event):

Does anybody have an idea how I can check for the aforementioned marker, when this method is called?

motion wrote:
ok, writing an own transaction manager is too much for my business case, so
I think I will live with the risk of getting out of sync and find a workaround to deal with the situation, if both systems are not congruent.

Martin, you mentioned, that I have to "... check for the LI marker on the request ...".
How do I do this check?

thank you for your efforts ....



Felipe Roquette () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
motion wrote:
On deletion, the method I registered as a subscriber is called three times.
...
I registered a subsriber for
Products.Archetypes.interfaces.IObjectInitializedEvent
 and for
zope.app.container.interfaces.IObjectRemovedEvent

The method signature for the notified delete-method is:
@adapter(IMyObject, IObjectRemovedEvent)
def deleteMyObject(self, event):

Does anybody have an idea how I can check for the aforementioned marker, when this method is called?
Man, I am stuck in the same problem.
I have to set an attribute of an object B, after deletion of object A, but:
- using IObjectRemovedEvent, my def is called three times
- none of these three call get attribute of B setted. It seems there is a roll-back and the transaction is not commited... I don't know.
- I have no idea how to check this marker

Regards,
Felipe Roquette
Martin Aspeli () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
Felipe Roquette wrote:

> Man, I am stuck in the same problem.
> I have to set an attribute of an object B, after deletion of object A, but:
> - using IObjectRemovedEvent, my def is called three times

I'm not quite sure why it'd be called three times. I would expect it to
be called twice. Note that if you have a folderish type, children of the
folder will also get the IObjectRemovedEvent.

If you can do this, it'd be helpful: put a breakpoint in the handler:

   def myhandler(obj, event):
       import pdb; pdb.set_trace()

Trigger the deletion. You should get the breakpoint three times (start
Zope in foreground mode, obviously). Each time, do this:

  (pdb) pp obj
  (pdb) pp event
  (pdb) pp event.object
  (pdb) bt


Paste the result of those three commands here. This will tell us (a) the
context, (b) the exact event type, (c) the real object of the event and
(d) the call stack up until the point where the event handler is called.

Also paste your event handler registration (i.e. the ZCML + method
signature).

> - none of these thre
e call get attribute of B setted. It seems there is a
> roll-back and the transaction is not commited... I don't know.

The way plone.app.linkintegrity works is this:

  1. The deletion is attempted
  2. An event handler checks if any links will be broken and marks those
in a special field on the request
  3. The transaction is aborted
  4. The user is asked to confirm
  5. If they confirm, the original request is replayed, but this time
the event handler doesn't abort the transaction

So, the last time, the transaction should definitely be committed.

The reason it works like this, by the way, is that it's very hard
otherwise to predict any and all situation in which there could be
broken links.

> - I have no idea how to check this marker

Untested, but you can try something like this:

from plone.app.linkintegrity.interfaces import ILinkIntegrityInfo

def myhandler(obj, event):
     request = getattr(obj, 'REQUEST', None)
     realDelete = False
     if request is None:
         realDelete = True
     else:
         info = ILinkIntegrityInfo(request)
         if not info.integrityCheckingEnabled():
             realDelete = True
         elif not info.getIntegrityBreaches():
             realDelete = True
         elif info.isConfirmedItem(obj):
             realDelete = True

     if realDelete:
         # do your thing

Cheers,
Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
motion () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
Hello,
Martin Aspeli wrote:
...
Trigger the deletion. You should get the breakpoint three times (start
Zope in foreground mode, obviously). Each time, do this:

  (pdb) pp obj
  (pdb) pp event
  (pdb) pp event.object
  (pdb) bt


Paste the result of those three commands here. This will tell us (a) the
context, (b) the exact event type, (c) the real object of the event and
(d) the call stack up until the point where the event handler is called.

Also paste your event handler registration (i.e. the ZCML + method
signature).
this is the registration of my subsriber:
in configure.zcml:
<subscriber handler=".tools.deleteMyObject" />

The function in tools.py:
@adapter(IPartnerAngebot, IObjectRemovedEvent)
def deleteMyObject(self, event):


This is the result of my debug messages for the three times, that my function is called on deletion.
I hope that you can read all lines, if not, I can try to upload a file with the messages.

Called the first time:
------------------------------------------------------------------------
(Pdb) pp self
<PartnerAngebot at /projectname/partner/partnername/partnerangebot>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0x107aea8c>
(Pdb) pp event.object
<PartnerAngebot at /projectname/partner/partnername/partnerangebot>
(Pdb) bt
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result = FSControllerPythonScript.inheritedAttribute('__call__')(self, *args, **kwargs)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/myname/Projekte/workspace/trunk/Script (Python)(9)delete_confirmation()
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFPlone/utils.py(821)isLinked()
-> parent.manage_delObjects(obj.getId())
  /home/myname/Projekte/workspace/trunk/parts/plone/Archetypes/BaseFolder.py(114)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/myname/Projekte/workspace/trunk/src/projectname.partner/projectname/partner/tools.py(116)deleteMyObject()->None
-> import pdb;pdb.set_trace()



Called the second time
------------------------------------------------------------------------
(Pdb) pp self
<PartnerAngebot at /projectname/partner/partnername/partnerangebot>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0x129c452c>
(Pdb) pp event.object
<PartnerAngebot at /projectname/partner/partnername/partnerangebot>
(Pdb) bt
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result = FSControllerPythonScript.inheritedAttribute('__call__')(self, *args, **kwargs)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/myname/Projekte/workspace/trunk/Script (Python)(9)delete_confirmation()
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFPlone/utils.py(821)isLinked()
-> parent.manage_delObjects(obj.getId())
  /home/myname/Projekte/workspace/trunk/parts/plone/Archetypes/BaseFolder.py(114)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/myname/Projekte/workspace/trunk/src/projectname.partner/projectname/partner/tools.py(116)deleteMyObject()->None
-> import pdb;pdb.set_trace()



Called the third time
---------------------------------------------------------------------------------------------
(Pdb) pp self
<PartnerAngebot at /projectname/partner/partnername/partnerangebot>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0x12ac99ec>
(Pdb) pp event.object
<PartnerAngebot at /projectname/partner/partnername/partnerangebot>
(Pdb) bt
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/FSControllerPythonScript.py(106)__call__()
-> return self.getNext(result, self.REQUEST)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/ControllerBase.py(231)getNext()
-> return next_action.getAction()(controller_state)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/Actions/TraverseTo.py(38)__call__()
-> REQUEST, bind=1)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/FSControllerPageTemplate.py(90)__call__()
-> return self._call(FSControllerPageTemplate.inheritedAttribute('__call__'), *args, **kwargs)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/BaseControllerPageTemplate.py(28)_call()
-> return self.getNext(controller_state, REQUEST)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/ControllerBase.py(231)getNext()
-> return next_action.getAction()(controller_state)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/Actions/TraverseTo.py(38)__call__()
-> REQUEST, bind=1)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result = FSControllerPythonScript.inheritedAttribute('__call__')(self, *args, **kwargs)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/myname/Projekte/workspace/trunk/parts/plone/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/myname/Projekte/workspace/trunk/Script (Python)(27)object_delete()
  /home/myname/Projekte/workspace/trunk/parts/plone/Archetypes/BaseFolder.py(114)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/myname/Projekte/workspace/trunk/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/myname/Projekte/workspace/trunk/src/projectname.partner/projectname/partner/tools.py(116)deleteMyObject()->None
-> import pdb;pdb.set_trace()


Can you find a reason with these information, why it is called three times?
Thank you very much for your efforts :)
Felipe Roquette () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
In reply to this post by Martin Aspeli
Hello Martin,

Em Seg, 2009-09-28 às 11:50 +0800, Martin Aspeli escreveu:
> I'm not quite sure why it'd be called three times. I would expect it to
> be called twice. Note that if you have a folderish type, children of the
> folder will also get the IObjectRemovedEvent.

You are right, more precisely ATFolder.

> Paste the result of those three commands here. This will tell us (a) the
> context, (b) the exact event type, (c) the real object of the event and
> (d) the call stack up until the point where the event handler is called.

First time occurs before the confirmation (file d1):

Debuging...
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) pp obj
*** NameError: <exceptions.NameError instance at 0xc311830>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0xc2ff290>
(Pdb) pp event.object
<Entry at /Teste/teste/october-2009/2009-10-01-20-55-53.177-gmt-3>
(Pdb) bt
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result =
FSControllerPythonScript.inheritedAttribute('__call__')(self, *args,
**kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/felipe/src/timesheet/Script (Python)(9)delete_confirmation()
  /home/felipe/.buildout/eggs/Plone-3.2.1-py2.4.egg/Products/CMFPlone/utils.py(821)isLinked()
-> parent.manage_delObjects(obj.getId())
  /home/felipe/.buildout/eggs/Products.Archetypes-1.5.10-py2.4.egg/Products/Archetypes/BaseFolder.py(116)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) c

Second and third occurs after confirmation.
Second (d2):
Debuging...
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) pp obj
*** NameError: <exceptions.NameError instance at 0xc35a908>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0xbd5d290>
(Pdb) pp event.object
<Entry at /Teste/teste/october-2009/2009-10-01-20-55-53.177-gmt-3>
(Pdb) bt
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result =
FSControllerPythonScript.inheritedAttribute('__call__')(self, *args,
**kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/felipe/src/timesheet/Script (Python)(9)delete_confirmation()
  /home/felipe/.buildout/eggs/Plone-3.2.1-py2.4.egg/Products/CMFPlone/utils.py(821)isLinked()
-> parent.manage_delObjects(obj.getId())
  /home/felipe/.buildout/eggs/Products.Archetypes-1.5.10-py2.4.egg/Products/Archetypes/BaseFolder.py(116)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) c

Third:
Debuging...
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) pp obj
*** NameError: <exceptions.NameError instance at 0xc35a0e0>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0xc2c2290>
(Pdb) pp event.object
<Entry at /Teste/teste/october-2009/2009-10-01-20-55-53.177-gmt-3>
(Pdb) bt
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(106)__call__()
-> return self.getNext(result, self.REQUEST)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/ControllerBase.py(231)getNext()
-> return next_action.getAction()(controller_state)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Actions/TraverseTo.py(38)__call__()
-> REQUEST, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPageTemplate.py(90)__call__()
-> return
self._call(FSControllerPageTemplate.inheritedAttribute('__call__'),
*args, **kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/BaseControllerPageTemplate.py(28)_call()
-> return self.getNext(controller_state, REQUEST)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/ControllerBase.py(231)getNext()
-> return next_action.getAction()(controller_state)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Actions/TraverseTo.py(38)__call__()
-> REQUEST, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result =
FSControllerPythonScript.inheritedAttribute('__call__')(self, *args,
**kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/felipe/src/timesheet/Script (Python)(27)object_delete()
  /home/felipe/.buildout/eggs/Products.Archetypes-1.5.10-py2.4.egg/Products/Archetypes/BaseFolder.py(116)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) c

> Also paste your event handler registration (i.e. the ZCML + method
> signature).

ZCML (zcml file):
<subscriber handler=".entry.entry_removed" />

Method (method file):
@adapter(IEntry, IObjectRemovedEvent)
def entry_removed(entry, event):
    print "Debuging..."
    import pdb
    pdb.set_trace()
    entry.heldPercentage = 0
    entry.updateHeldPercentage()


> The way plone.app.linkintegrity works is this:
>
>   1. The deletion is attempted
>   2. An event handler checks if any links will be broken and marks those
> in a special field on the request
>   3. The transaction is aborted
>   4. The user is asked to confirm
>   5. If they confirm, the original request is replayed, but this time
> the event handler doesn't abort the transaction

Does it replay my entry_removed() method or only the content deletion?

> Untested, but you can try something like this:
>
> def myhandler(obj, event):
>      request = getattr(obj, 'REQUEST', None)
>      realDelete = False
>      if request is None:
>          realDelete = True
>      else:
>          info = ILinkIntegrityInfo(request)
>          if not info.integrityCheckingEnabled():
>              realDelete = True
>          elif not info.getIntegrityBreaches():
>              realDelete = True
>          elif info.isConfirmedItem(obj):
>              realDelete = True
>
>      if realDelete:
>          # do your thing
realDelete never gets True.
I was looking the source... isConfirmedItem(obj) shoud be True after confirmation, right? But it seems there is no marker (link_integrity_info) or there is no info about this marker on the request (self.context.environ.get(self.marker, []) always returns []) so isConfirmedItem doesn't get True.

Thank you Martin!

Regards,
Felipe Roquette
________________________________________________________________________
Krei Tecnologia Ltda
www.krei.com.br

Debuging...
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) pp obj
*** NameError: <exceptions.NameError instance at 0xc311830>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0xc2ff290>
(Pdb) pp event.object
<Entry at /Teste/teste/october-2009/2009-10-01-20-55-53.177-gmt-3>
(Pdb) bt
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result = FSControllerPythonScript.inheritedAttribute('__call__')(self, *args, **kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/felipe/src/timesheet/Script (Python)(9)delete_confirmation()
  /home/felipe/.buildout/eggs/Plone-3.2.1-py2.4.egg/Products/CMFPlone/utils.py(821)isLinked()
-> parent.manage_delObjects(obj.getId())
  /home/felipe/.buildout/eggs/Products.Archetypes-1.5.10-py2.4.egg/Products/Archetypes/BaseFolder.py(116)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) c

Debuging...
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) pp obj
*** NameError: <exceptions.NameError instance at 0xc35a908>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0xbd5d290>
(Pdb) pp event.object
<Entry at /Teste/teste/october-2009/2009-10-01-20-55-53.177-gmt-3>
(Pdb) bt
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result = FSControllerPythonScript.inheritedAttribute('__call__')(self, *args, **kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/felipe/src/timesheet/Script (Python)(9)delete_confirmation()
  /home/felipe/.buildout/eggs/Plone-3.2.1-py2.4.egg/Products/CMFPlone/utils.py(821)isLinked()
-> parent.manage_delObjects(obj.getId())
  /home/felipe/.buildout/eggs/Products.Archetypes-1.5.10-py2.4.egg/Products/Archetypes/BaseFolder.py(116)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) c

Debuging...
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) pp obj
*** NameError: <exceptions.NameError instance at 0xc35a0e0>
(Pdb) pp event
<zope.app.container.contained.ObjectRemovedEvent object at 0xc2c2290>
(Pdb) pp event.object
<Entry at /Teste/teste/october-2009/2009-10-01-20-55-53.177-gmt-3>
(Pdb) bt
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZServer/PubCore/ZServerPublisher.py(25)__init__()
-> response=b)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(401)publish_module()
-> environ, debug, request, response)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(202)publish_module_standard()
-> response = publish(request, module_name, after_list, debug=debug)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(119)publish()
-> request, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(106)__call__()
-> return self.getNext(result, self.REQUEST)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/ControllerBase.py(231)getNext()
-> return next_action.getAction()(controller_state)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Actions/TraverseTo.py(38)__call__()
-> REQUEST, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPageTemplate.py(90)__call__()
-> return self._call(FSControllerPageTemplate.inheritedAttribute('__call__'), *args, **kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/BaseControllerPageTemplate.py(28)_call()
-> return self.getNext(controller_state, REQUEST)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/ControllerBase.py(231)getNext()
-> return next_action.getAction()(controller_state)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Actions/TraverseTo.py(38)__call__()
-> REQUEST, bind=1)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/mapply.py(88)mapply()
-> if debug is not None: return debug(object,args,context)
  /home/felipe/src/timesheet/parts/zope2/lib/python/ZPublisher/Publish.py(42)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/FSControllerPythonScript.py(104)__call__()
-> result = FSControllerPythonScript.inheritedAttribute('__call__')(self, *args, **kwargs)
  /home/felipe/.buildout/eggs/Products.CMFFormController-2.1.2-py2.4.egg/Products/CMFFormController/Script.py(145)__call__()
-> return BaseFSPythonScript.__call__(self, *args, **kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(140)__call__()
-> return Script.__call__(self, *args, **kw)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(313)__call__()
-> return self._bindAndExec(args, kw, None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/Shared/DC/Scripts/Bindings.py(350)_bindAndExec()
-> return self._exec(bound_data, args, kw)
  /home/felipe/.buildout/eggs/Products.CMFCore-2.1.2-py2.4.egg/Products/CMFCore/FSPythonScript.py(196)_exec()
-> result = f(*args, **kw)
  /home/felipe/src/timesheet/Script (Python)(27)object_delete()
  /home/felipe/.buildout/eggs/Products.Archetypes-1.5.10-py2.4.egg/Products/Archetypes/BaseFolder.py(116)manage_delObjects()
-> return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(524)manage_delObjects()
-> self._delObject(id)
  /home/felipe/src/timesheet/parts/zope2/lib/python/OFS/ObjectManager.py(396)_delObject()
-> notify(ObjectRemovedEvent(ob, self, id))
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/event/__init__.py(23)notify()
-> subscriber(event)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(26)dispatch()
-> for ignored in zope.component.subscribers(event, None):
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/event.py(33)objectEventNotify()
-> adapters = zope.component.subscribers((event.object, event), None)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/_api.py(130)subscribers()
-> return sitemanager.subscribers(objects, interface)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/component/registry.py(290)subscribers()
-> return self.adapters.subscribers(objects, provided)
  /home/felipe/src/timesheet/parts/zope2/lib/python/zope/interface/adapter.py(535)subscribers()
-> subscription(*objects)
> /home/felipe/src/timesheet/src/krei.timeSheet/krei/timeSheet/content/entry.py(228)entry_removed()
-> entry.heldPercentage = 0
(Pdb) c

@adapter(IEntry, IObjectRemovedEvent)
def entry_removed(entry, event):
    print "Debuging..."
    import pdb
    pdb.set_trace()
    entry.heldPercentage = 0
    entry.updateHeldPercentage()


<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:five="http://namespaces.zope.org/five"
    i18n_domain="krei.timeSheet">

    <!-- Declare security for the field properties of the various content
         types, and register other components, such as validation subscription
         adapters, event subscribers (for adding a portlet to a newly created
         cinema folder), and adapter factories.
       
      -->
    <subscriber handler=".entry.entry_changed" />

    <subscriber handler=".entry.entry_initialized" />

    <subscriber handler=".entry.entry_added" />

    <subscriber handler=".entry.entry_removed" />
</configure>

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Felipe Roquette () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
It's me again.

Em Sex, 2009-10-02 às 11:10 -0300, Felipe Roquette escreveu:
> realDelete never gets True.

        Now I realized what link integrity does, it is just for <a> and <img>,
not for content references.
        I disabled LI and realDelete (obviously) gets True.
        After that I found where was the problem: my object looses its
reference to the other object on the IObjectRemovedEvent. I don't know
why but somewhere my object reference is erased.
        I made a workaround and now my code is playing nice.

Thanks Martin! I think LI was not the problem.

Regards,
Felipe Roquette

________________________________________________________________________
Krei Tecnologia Ltda
www.krei.com.br


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Martin Aspeli () Re: Event on object deletion
Reply Threaded More More options
Print post
Permalink
Felipe Roquette wrote:
> It's me again.
>
> Em Sex, 2009-10-02 às 11:10 -0300, Felipe Roquette escreveu:

   ^^^^---- looks like something Limi might be thinking about doing with
negative margins.

>> realDelete never gets True.
>
> Now I realized what link integrity does, it is just for <a> and <img>,
> not for content references.
> I disabled LI and realDelete (obviously) gets True.
> After that I found where was the problem: my object looses its
> reference to the other object on the IObjectRemovedEvent. I don't know
> why but somewhere my object reference is erased.
> I made a workaround and now my code is playing nice.
>
> Thanks Martin! I think LI was not the problem.

Well, references are deleted in an event handler too. References are
stored centrally in the reference catalog. So depending on when your
handler is called, that clearing may have happened already.

There's an IBeforeObjectRemovedEvent that you can use too, where they
should stay put.

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users