manage_pasteObjects in manage_afterAdd raises AttributeError for getPhysicalRoot
Hi, below an issue I don't have any idea where the problem lies. Are there some experts around that could give me some advice? Thanks! The code is for the redesign of the swiss community site http://www.zope.ch hopefully working in two weeks. So please, help! Are there any known issues copy&pasting a freshly added object A to another folderish object I in the A's manage_afterAdd hook? Doing Copy&Paste by hand (by GUI) after the object A was added works. Have a look at the simplified code snippet (Python Product): def manage_afterAdd(self, item, container): """ simplified code called after instanation of object A (self) in folder P (container) """ index_obj = getattr(container.aq_base, 'index_html', None) if (index_obj is not None) and (index_obj.meta_type == self.meta_type): # P has an object I (index_obj) of the same type as A is index_obj.addToCollection(container._getOb(self.getId())) def addToCollection(self, obj): """ simplified code in the same class called on index_html object """ container = obj.getParentNode() id = obj.getId() # this copies object A (obj, just instanated before manage_afterAdd!!!) # to object I (self, same as index_obj above) self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below Greg ------------------------------------------------------------------------- Error Type: AttributeError Error Value: getPhysicalRoot Traceback (innermost last): File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 150, in publish_module File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 114, in publish File D:\prog\ZOPE_T~1\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook (Object: gregweb) File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 98, in publish File D:\prog\ZOPE_T~1\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: createObject) File E:\user\greg\data\zope_test\Products\CMFCore\FSPythonScript.py, line 90, in __call__ (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in __call__ (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in _bindAndExec (Object: createObject) File E:\user\greg\data\zope_test\Products\CMFCore\FSPythonScript.py, line 124, in _exec (Object: createObject) (Info: ({'script': <FSPythonScript instance at 018E4DD0>, 'context': <PloneFolder instance at 0227A820>, 'container': <CMFSite instance at 0227D278>, 'traverse_subpath': []}, (None, 'Manual Collection'), {}, (None, None))) File Script (Python), line 12, in createObject File E:\user\greg\data\zope_test\Products\CMFCore\PortalFolder.py, line 362, in invokeFactory (Object: gregweb) File E:\user\greg\data\zope_test\Products\CMFCore\TypesTool.py, line 824, in constructContent (Object: portal_types) File E:\user\greg\data\zope_test\Products\CMFCore\TypesTool.py, line 513, in constructInstance (Object: Manual Collection) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py, line 84, in addManualCollection ##### this is the factory !!! File D:\prog\ZOPE_T~1\lib\python\OFS\ObjectManager.py, line 267, in _setObject (Object: gregweb) ##### parent object P (Folder) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py, line 270, in manage_afterAdd (Object: Manual_Collection.2002-09-24.1731) ##### object A to be copied (folderish) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py, line 675, in addToCollection (Object: index_html) ##### target object index_html (the target, also folderish) File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in manage_pasteObjects (Object: index_html) AttributeError: (see above) _____________________________________ Grégoire Weber mailto:gregoire.weber@switzerland.org
Grégoire Weber wrote:
Hi,
below an issue I don't have any idea where the problem lies. Are there some experts around that could give me some advice? Thanks! The code is for the redesign of the swiss community site http://www.zope.ch hopefully working in two weeks. So please, help!
Are there any known issues copy&pasting a freshly added object A to another folderish object I in the A's manage_afterAdd hook?
Doing Copy&Paste by hand (by GUI) after the object A was added works.
Have a look at the simplified code snippet (Python Product):
def manage_afterAdd(self, item, container): """ simplified code called after instanation of object A (self) in folder P (container) """ index_obj = getattr(container.aq_base, 'index_html', None) if (index_obj is not None) and (index_obj.meta_type == self.meta_type): # P has an object I (index_obj) of the same type as A is index_obj.addToCollection(container._getOb(self.getId()))
def addToCollection(self, obj): """ simplified code in the same class called on index_html object """ container = obj.getParentNode() id = obj.getId()
# this copies object A (obj, just instanated before manage_afterAdd!!!) # to object I (self, same as index_obj above) self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below ^^^^^^^
Not sure, but shouldn't 'context' be 'self'? I'm not sure because that doesn't seem to be the error that you are seeing. I would have thought that the use of 'context' would raise a NameError (or something like that). tim
index_obj.addToCollection(container._getOb(self.getId()))
self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below
Looks like you are calling manage_pasteObjects on self, which is the index_html object, rather than on the container. You should really be doing container.addToCollection(..). -- Andy McKay www.agmweb.ca ----- Original Message ----- From: "Grégoire Weber" <gregoire.weber@switzerland.org> To: <zope@zope.org> Sent: Tuesday, September 24, 2002 8:07 AM Subject: [Zope] manage_pasteObjects in manage_afterAdd raises AttributeError for getPhysicalRoot Hi, below an issue I don't have any idea where the problem lies. Are there some experts around that could give me some advice? Thanks! The code is for the redesign of the swiss community site http://www.zope.ch hopefully working in two weeks. So please, help! Are there any known issues copy&pasting a freshly added object A to another folderish object I in the A's manage_afterAdd hook? Doing Copy&Paste by hand (by GUI) after the object A was added works. Have a look at the simplified code snippet (Python Product): def manage_afterAdd(self, item, container): """ simplified code called after instanation of object A (self) in folder P (container) """ index_obj = getattr(container.aq_base, 'index_html', None) if (index_obj is not None) and (index_obj.meta_type == self.meta_type): # P has an object I (index_obj) of the same type as A is index_obj.addToCollection(container._getOb(self.getId())) def addToCollection(self, obj): """ simplified code in the same class called on index_html object """ container = obj.getParentNode() id = obj.getId() # this copies object A (obj, just instanated before manage_afterAdd!!!) # to object I (self, same as index_obj above) self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below Greg ------------------------------------------------------------------------- Error Type: AttributeError Error Value: getPhysicalRoot Traceback (innermost last): File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 150, in publish_module File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 114, in publish File D:\prog\ZOPE_T~1\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook (Object: gregweb) File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 98, in publish File D:\prog\ZOPE_T~1\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: createObject) File E:\user\greg\data\zope_test\Products\CMFCore\FSPythonScript.py, line 90, in __call__ (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in __call__ (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in _bindAndExec (Object: createObject) File E:\user\greg\data\zope_test\Products\CMFCore\FSPythonScript.py, line 124, in _exec (Object: createObject) (Info: ({'script': <FSPythonScript instance at 018E4DD0>, 'context': <PloneFolder instance at 0227A820>, 'container': <CMFSite instance at 0227D278>, 'traverse_subpath': []}, (None, 'Manual Collection'), {}, (None, None))) File Script (Python), line 12, in createObject File E:\user\greg\data\zope_test\Products\CMFCore\PortalFolder.py, line 362, in invokeFactory (Object: gregweb) File E:\user\greg\data\zope_test\Products\CMFCore\TypesTool.py, line 824, in constructContent (Object: portal_types) File E:\user\greg\data\zope_test\Products\CMFCore\TypesTool.py, line 513, in constructInstance (Object: Manual Collection) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py , line 84, in addManualCollection ##### this is the factory !!! File D:\prog\ZOPE_T~1\lib\python\OFS\ObjectManager.py, line 267, in _setObject (Object: gregweb) ##### parent object P (Folder) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py , line 270, in manage_afterAdd (Object: Manual_Collection.2002-09-24.1731) ##### object A to be copied (folderish) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py , line 675, in addToCollection (Object: index_html) ##### target object index_html (the target, also folderish) File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in manage_pasteObjects (Object: index_html) AttributeError: (see above) _____________________________________ Grégoire Weber mailto:gregoire.weber@switzerland.org _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Hi Andy, thats right (its intended to call paste on the index_html object). index_html is folderish also. For now it is not important, that this its id is index_html. Correctly said I hope it is not relevant. By hand I can paste the object into index_html (paste knob in plone). thanks for your answer anyway. Greg At 10:15 24.09.2002 -0700, Andy McKay wrote:
index_obj.addToCollection(container._getOb(self.getId()))
self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below
Looks like you are calling manage_pasteObjects on self, which is the index_html object, rather than on the container. You should really be doing container.addToCollection(..). -- Andy McKay www.agmweb.ca
----- Original Message ----- From: "Grégoire Weber" <gregoire.weber@switzerland.org> To: <zope@zope.org> Sent: Tuesday, September 24, 2002 8:07 AM Subject: [Zope] manage_pasteObjects in manage_afterAdd raises AttributeError for getPhysicalRoot
Hi,
below an issue I don't have any idea where the problem lies. Are there some experts around that could give me some advice? Thanks! The code is for the redesign of the swiss community site http://www.zope.ch hopefully working in two weeks. So please, help!
Are there any known issues copy&pasting a freshly added object A to another folderish object I in the A's manage_afterAdd hook?
Doing Copy&Paste by hand (by GUI) after the object A was added works.
Have a look at the simplified code snippet (Python Product):
def manage_afterAdd(self, item, container): """ simplified code called after instanation of object A (self) in folder P (container) """ index_obj = getattr(container.aq_base, 'index_html', None) if (index_obj is not None) and (index_obj.meta_type == self.meta_type): # P has an object I (index_obj) of the same type as A is index_obj.addToCollection(container._getOb(self.getId()))
def addToCollection(self, obj): """ simplified code in the same class called on index_html object """ container = obj.getParentNode() id = obj.getId()
# this copies object A (obj, just instanated before manage_afterAdd!!!) # to object I (self, same as index_obj above) self.manage_pasteObjects(container.manage_copyObjects(id)) # raises ERROR below
Greg
------------------------------------------------------------------------- Error Type: AttributeError Error Value: getPhysicalRoot
Traceback (innermost last): File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 150, in publish_module File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 114, in publish File D:\prog\ZOPE_T~1\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook (Object: gregweb) File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 98, in publish File D:\prog\ZOPE_T~1\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: createObject) File E:\user\greg\data\zope_test\Products\CMFCore\FSPythonScript.py, line 90, in __call__ (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in __call__ (Object: createObject) File D:\prog\ZOPE_T~1\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in _bindAndExec (Object: createObject) File E:\user\greg\data\zope_test\Products\CMFCore\FSPythonScript.py, line 124, in _exec (Object: createObject) (Info: ({'script': <FSPythonScript instance at 018E4DD0>, 'context': <PloneFolder instance at 0227A820>, 'container': <CMFSite instance at 0227D278>, 'traverse_subpath': []}, (None, 'Manual Collection'), {}, (None, None))) File Script (Python), line 12, in createObject File E:\user\greg\data\zope_test\Products\CMFCore\PortalFolder.py, line 362, in invokeFactory (Object: gregweb) File E:\user\greg\data\zope_test\Products\CMFCore\TypesTool.py, line 824, in constructContent (Object: portal_types) File E:\user\greg\data\zope_test\Products\CMFCore\TypesTool.py, line 513, in constructInstance (Object: Manual Collection) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py , line 84, in addManualCollection ##### this is the factory !!! File D:\prog\ZOPE_T~1\lib\python\OFS\ObjectManager.py, line 267, in _setObject (Object: gregweb) ##### parent object P (Folder) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py , line 270, in manage_afterAdd (Object: Manual_Collection.2002-09-24.1731) ##### object A to be copied (folderish) File E:\user\greg\data\zope_test\Products\CMFManualCollection\ManualCollection.py , line 675, in addToCollection (Object: index_html) ##### target object index_html (the target, also folderish) File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in manage_pasteObjects (Object: index_html) AttributeError: (see above) _____________________________________ Grégoire Weber mailto:gregoire.weber@switzerland.org
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_____________________________________ Grégoire Weber Rigistr. 31 CH-8006 Zürich Switzerland phone: +41-(0)1-361 66 11 mobile: +41-(0)79-44 11 457 mailto:gregoire.weber@switzerland.org
=?iso-8859-1?Q?Gr=E9goire?= Weber writes:
... def addToCollection(self, obj): ... self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below ------------------------------------------------------------------------- Error Type: AttributeError Error Value: getPhysicalRoot
Traceback (innermost last): File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in manage_pasteObjects (Object: index_html) AttributeError: (see above) This means, "self" above, does not have a method "getPhysicalRoot".
This may be because it is only partially acquisiton wrapped. Usually, you should check for attribute existence with "aq_base" but access without the "aq_base". I.e., you should use the following idiom: if hasattr(aq_base(obj),'some_attribute'): my_attribute= getattr(obj,'some_attribute') ... Dieter
Hi Dieter, Hi All, AttributeError / getPhysicalRoot has gone changing index_obj = getattr(container.aq_base, 'index_html', None) to if hasattr(container.aq_base, 'index_html'): index_obj = getattr(container, 'index_html') else: index_obj = None I thought they were equivalent -- they're not !!! Can somebody confirm that (inclusive reasons)? Gruss, Gregoire ----------------------------------------------------------------------- <CODE working="correct"> def manage_afterAdd(self, item, container): """ simplified code called after instanation of object A (self) in folder P (container) """ if hasattr(container.aq_base, 'index_html'): index_obj = getattr(container, 'index_html') if index_obj.meta_type == self.meta_type: # P has an object I (index_obj) of the same type as A is index_obj.addToCollection(container, self.getId()) def addToCollection(self, container, id): """ simplified code in the same class called on index_html object """ # this copies object A (container/id, just instanated before # manage_afterAdd!!!) to object I (self, same as index_obj above) cb = container.manage_copyObjects(id) # OK self.manage_pasteObjects(cb) # raises ERROR (same as before) </CODE> At 22:16 24.09.2002 +0200, Dieter Maurer wrote:
=?iso-8859-1?Q?Gr=E9goire?= Weber writes:
... def addToCollection(self, obj): ... self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below ------------------------------------------------------------------------- Error Type: AttributeError Error Value: getPhysicalRoot
Traceback (innermost last): File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in manage_pasteObjects (Object: index_html) AttributeError: (see above) This means, "self" above, does not have a method "getPhysicalRoot".
This may be because it is only partially acquisiton wrapped.
Usually, you should check for attribute existence with "aq_base" but access without the "aq_base".
I.e., you should use the following idiom:
if hasattr(aq_base(obj),'some_attribute'): my_attribute= getattr(obj,'some_attribute') ...
Dieter
_____________________________________ Grégoire Weber mailto:gregoire.weber@switzerland.org
=?iso-8859-1?Q?Gr=E9goire?= Weber writes:
AttributeError / getPhysicalRoot has gone changing
index_obj = getattr(container.aq_base, 'index_html', None)
to
if hasattr(container.aq_base, 'index_html'): index_obj = getattr(container, 'index_html') else: index_obj = None
I thought they were equivalent -- they're not !!!
Can somebody confirm that (inclusive reasons)? I can.
"container.aq_base" is "container" without any acquisition context. "getattr(container.aq_base,attr)" is "attr" in the context of "container.aq_base". Further acquisition context is missing. "getattr(container,attr)" is "attr" in the context of "container". It has full acquisition context. If it is not clear, read the "Acquisition" section in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> and draw some acquisition trees. Dieter
Sorry Dieter and thanks a lot, it was too late, when I read your e-mail below, so I missed the point ('Usually, you should check ...) and had to find it out by myself ... grmpf :-(. Greg At 22:16 24.09.2002 +0200, you wrote:
=?iso-8859-1?Q?Gr=E9goire?= Weber writes:
... def addToCollection(self, obj): ... self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below ------------------------------------------------------------------------- Error Type: AttributeError Error Value: getPhysicalRoot
Traceback (innermost last): File D:\prog\zope_test\lib\python\OFS\CopySupport.py, line 144, in manage_pasteObjects (Object: index_html) AttributeError: (see above) This means, "self" above, does not have a method "getPhysicalRoot".
This may be because it is only partially acquisiton wrapped.
Usually, you should check for attribute existence with "aq_base" but access without the "aq_base".
I.e., you should use the following idiom:
if hasattr(aq_base(obj),'some_attribute'): my_attribute= getattr(obj,'some_attribute') ...
Dieter
_____________________________________ Grégoire Weber mailto:gregoire.weber@switzerland.org
participants (4)
-
Andy McKay -
Dieter Maurer -
Grégoire Weber -
Tim Hicks