[Zope-dev] ZClass inside a ZClass

Martijn Faassen m.faassen@vet.uu.nl
Wed, 27 Oct 1999 18:36:30 +0200


Hi there,

I'm having some problems with ZClasses within an ObjectManager ZClass.

[later: ahum, I *had *some problems. I'll leave this mail as an
interesting debugging artifact; it perhaps also points out some bugs in
Zope]

* What am I trying to do?

I have a FormulatorForm ZClass. Instances of FormulatorForm can contain
instances of ZClasses (IntegerField, StringField, etc). Those field
ZClasses should only be able to create inside FormulatorForm instances,
nowhere else.

* How far did I get?

I have created a ZClass FormulatorForm. Inside I've created my Field
ZClasses (4 of them right now). I've also let Zope autogenerate the
constructor methods. This all appears to work.

* What is wrong then?

First I had created the Field ZClasses as global ZClasses; they could be
created anywhere. I tried to move them inside the new FormulatorForm
ZClass, and this worked; only the permissions wouldn't move from the
root of the Product.

It all seemed to work, but the field ZClasses show up *twice* each in
the add list of a FormulatorForm instance.

I messed around a bit with creating and disabling factories,
permissions, I forget what. I had one field ZClass show up only once
then, but then I got an error when trying to add it.

Not daunted, I removed all Field ZClasses and added them again from
scratch (not a big deal as they were mostly inheriting from Python base
classes). My experimenting, I thought, showed that this would fix the
problems. Nada. They still show up twice. What do I do now?

* What did you do to solve the problem? (added after I wrote the above
and I started figuring things out on my own)

Ooh, wait, I have just noticed that when I add a ZClass by hand which
doesn't inherit from any Python base class, the problem does not occur.
And *now* I have figured out that I should not name the Python base
classes the same as the ZClasses (my Python base class is called
StringField, while the ZClass inheriting from it is also called that).
This seems to be the source of the problem. Do not give your ZClass the
same name as the Python base class it inherits from! This appears to be,
if not a Zope bug, at least a severe Zope unclarity.

Having created a ZClass with a different name, all works, except that I
run into the resource not found bug (I did *not* run into that one
before with my other bug! :). Luckily there's a howto on how to fix
that, which worked:

http://www.zope.org/Members/gtk/containers

Phew. I hope the Zope version in CVS fixes both problems. :)

Regards,

Martijn