Switch from IObjectRemovedEvent to IIntIdRemovedEvent to avoid objects being unregistered before being removed from catalog
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 14:34:38 +0200
changeset 26 4f3937b02ba5
parent 25 b1f69674f011
child 27 47291be5bb8f
Switch from IObjectRemovedEvent to IIntIdRemovedEvent to avoid objects being unregistered before being removed from catalog
src/pyams_catalog/site.py
--- a/src/pyams_catalog/site.py	Wed Jul 12 14:23:51 2017 +0200
+++ b/src/pyams_catalog/site.py	Mon Sep 11 14:34:38 2017 +0200
@@ -21,8 +21,8 @@
 from hypatia.interfaces import ICatalog
 from persistent.interfaces import IPersistent
 from pyams_utils.interfaces.site import ISiteGenerations
-from zope.intid.interfaces import IIntIds
-from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectRemovedEvent, IObjectModifiedEvent
+from zope.intid.interfaces import IIntIds, IIntIdRemovedEvent
+from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent
 from zope.site.interfaces import INewLocalSite
 
 # import packages
@@ -94,8 +94,12 @@
         reindex_object(event.object, catalog)
 
 
-@subscriber(IObjectRemovedEvent, context_selector=IPersistent)
+@subscriber(IIntIdRemovedEvent, context_selector=IPersistent)
 def handle_removed_object(event):
-    """Un-index removed object"""
+    """Un-index removed object
+
+    Don't use IObjectRemovedEvent to avoid objects from being already unregistered
+    from IIntId utility!!!
+    """
     for name, catalog in get_utilities_for(ICatalog):
         unindex_object(event.object, catalog)