[Zope] Creating a ZClass instance as a method of another ZClass?

Jeff K. Hoffman jkhoffman@carolina.rr.com
Fri, 10 Dec 1999 12:11:49 -0500 (EST)


Hello, everyone.

I have just run into an interesting situation regarding ZClasses. Here's a
description of my setup (using Zope 2.1.0):

  o ProductB contains a ZClass called BClass, which inherits from Folder.
    o BClass implements several DTML Methods.
  o ProductA contains a ZClass called AClass, which inherits from Folder.
    o AClass implements several DTML Methods, and needs to contain an
      instance of BClass as a method.

Things went fine, until I tried to create the BClass instance in AClass's
Methods tab. I get the following error:

-----
  Traceback (innermost last):
  File /d.local/zope/lib/python/ZPublisher/Publish.py, line 214, in
publish_module
  File /d.local/zope/lib/python/ZPublisher/Publish.py, line 179, in
publish
  File /d.local/zope/lib/python/Zope/__init__.py, line 202, in
zpublisher_exception_hook
    (Object: RoleManager)
  File /d.local/zope/lib/python/ZPublisher/Publish.py, line 165, in
publish
  File /d.local/zope/lib/python/ZPublisher/mapply.py, line 160, in mapply
    (Object: BClass_add)
  File /d.local/zope/lib/python/ZPublisher/Publish.py, line 102, in
call_object
    (Object: BClass_add)
  File /d.local/zope/lib/python/OFS/DTMLMethod.py, line 145, in __call__
    (Object: BClass_add)
  File /d.local/zope/lib/python/DocumentTemplate/DT_String.py, line 502,
in __call__
    (Object: BClass_add)
  File /d.local/zope/lib/python/DocumentTemplate/DT_With.py, line 133, in
render
    (Object: BClass.createInObjectManager(REQUEST['id'], REQUEST))
  File /d.local/zope/lib/python/DocumentTemplate/DT_Util.py, line 335, in
eval
    (Object: BClass.createInObjectManager(REQUEST['id'], REQUEST))
    (Info: REQUEST)
  File <string>, line 0, in ?
  File /d.local/zope/lib/python/ZClasses/ZClass.py, line 454, in
createInObjectManager
    (Object: BClass)
AttributeError: (see above)
-----

Running this through the debugger, I found that the error occurs when, on
line 454 as noted in the traceback, the following line is executed in
createInObjectManager:

  return getattr(folder, id)

With the cursor sitting on this line in the debugger, I tried:

  pdb> p folder[id]
  <BClass instance at ...>
  pdb> s # this executes the getattr(folder, id) line
  AttributeError: 'binstance'

It is obvious that my instance has been created, and installed into the
methods instance via _setObject(), so I am baffled as to why folder[id]
works but getattr(folder, id) does not.

Can anyone shed any light on this, for me? Am I trying to do something
that's outside the capabilities of ZClasses, or have I just missed
something obvious?

Thanks,

--Jeff