[ZCM] [ZC] 1853/ 2 Comment "MountedObject calls manage_afterAdd w/o context"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Wed Jul 27 18:07:37 EDT 2005


Issue #1853 Update (Comment) "MountedObject calls manage_afterAdd w/o context"
 Status Accepted, Zope/bug+solution medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/1853

==============================================================
= Comment - Entry #2 by Tiran on Jul 27, 2005 6:07 pm

typo:
setMountPoint(container, faux.id, mo) should be  setMountPoint(container, mo.id, mo)

________________________________________
= Request - Entry #1 by Tiran on Jul 27, 2005 6:05 pm

 Status: Pending => Accepted

 Supporters added: chrism

The CustomTrailblazer is using context._setObject() where context is the application root and not the context where the object is created. _setObject() calls manage_afterAdd(). Some products are depending on the fact that manage_afterAdd() is called in the context where the object gets created.

Later in manage_addMountPoints() an evil trick is used work around the premature call of manage_afterAdd(). A fake (faux) folder is added first using _setObject() in the real context and than the real object replaces the fake with _setOb(). 

My patch replaces the _setObject() call in the blazer with _setOb() and removes the faux folder dance. manage_afterAdd() is called once in the context of the parent folder of the new mount point.

With my patch it is possible to use an ATContentTypes ATFolder as a container-class. W/o my patch it breaks because manage_afterAdd() isn't able to find some tools in the root of  the portal.

Chris you have more knowledge about the stuff. Do you think my patch is safe?

The patch:
Index: lib/python/Products/ZODBMountPoint/MountedObject.py
===================================================================
--- lib/python/Products/ZODBMountPoint/MountedObject.py (revision 37489)
+++ lib/python/Products/ZODBMountPoint/MountedObject.py (working copy)
@@ -103,7 +103,7 @@
         klass = jar.db().classFactory(jar, self.module_name, self.class_name)
         obj = klass(id)
         obj._setId(id)
-        context._setObject(id, obj)
+        context._setOb(id, obj)
         obj = context.unrestrictedTraverse(id)
         # Commit a subtransaction to assign the new object to
         # the correct database.
@@ -301,14 +301,14 @@
         # Add a faux object to avoid generating manage_afterAdd() events
         # while appeasing OFS.ObjectManager._setObject(), then discreetly
         # replace the faux object with a MountedObject.
-        faux = Folder()
-        faux.id = mo.id
-        faux.meta_type = loaded.meta_type
-        container._setObject(faux.id, faux)
+        #faux = Folder()
+        #faux.id = mo.id
+        #faux.meta_type = loaded.meta_type
+        #container._setObject(faux.id, faux)
         # DM 2005-05-17: we want to keep our decision about automatic
         #  mount point creation
         #del mo._create_mount_points
-        container._setOb(faux.id, mo)
+        container._setObject(mo.id, mo)
         setMountPoint(container, faux.id, mo)
         count += 1
     if REQUEST is not None:                     
==============================================================



More information about the Zope-Collector-Monitor mailing list