[Zope-dev] [Zope3-Users] Next Step to Bug Resolution???

Dan Korostelev nadako at gmail.com
Fri Jan 16 17:28:51 EST 2009


Hi Tim.

Unfortunately I didn't follow the discussion lately, so may be the
problem is no more, but...

I just committed a fix for zope.schema's ValidationError that makes
its repr output more sensible. I'd like community to review those
changes and say if they're okay, because changing exception formatting
syntax will affect doctest so they should be adapted to new style. But
I think it's better to adapt the doctests than to make debugging
difficulties for our users, right? :)

About your problem, here's the minimal failing example.

from zope.interface import Interface, implements
from zope.schema import Field, Object, Int
from zope.schema.interfaces import IField
from zope.schema.fieldproperty import FieldProperty

class IObjectId(IField):

    value = Int()

class ObjectId(Field):

    implements(IObjectId)

    value = FieldProperty(IObjectId['value'])

class IObjectRef(Interface):

    oid = Object(IObjectId)

class ObjectRef(object):

    implements(IField)

    oid = FieldProperty(IObjectRef['oid'])

oid = ObjectId()
oid.value = 3

ref = ObjectRef()
ref.oid = oid

Basically, it fails validation because the IField interface defines
some attributes (like default and missing_value) that are not set in
the Field base class and neither in ObjectId. So the exceptions are
really RequiredMissing.

But the general problem is still that you are misusing Field class as
base for your not-fieldy class. It defines specific functionality for
describing interface schemas and can be treated specially by other
components. If all you need is its "title" and "description" fields,
just define a base interface and implementation like:

class IItem(Interface):

    title = TextLine(title=u'Title', required=True)
    description = Text(title=u'Description', required=False)

class Item(Persistent):

    implements(IItem)

    title = FieldProperty(IItem['title'])
    description = FieldProperty(IItem['description'])

...and use them as base for your objects.

Hope this helps.

-- 
WBR, Dan Korostelev


More information about the Zope-Dev mailing list