[Zope3-Users] Why does schema validation not work in this example?

Michael Howitz mh at gocept.com
Sun Jan 18 09:31:15 EST 2009


Am 18.01.2009 um 09:26 schrieb Sebastian Bartos:
> Hello folks,
> I just played around with the validation of the schemata and created  
> the
> example listed below. According to the book by Philip it should rase a
> validation exception at the end. That's what the FieldProperty is
> supposed to do, but it does not do it here. (Tested in the zope debug
> console) Why?
>
> from zope.interface import Interface, implements
> from zope.schema import Int
> from zope.schema.fieldproperty import FieldProperty
>
> class ITest(Interface):
>    number = Int( title = u'A number' )
>
> class test(object):
>    implements(ITest)
>    number = FieldProperty(ITest['number'])
>
> test_class = test()
> print test.number  # get <zope.schema.fieldproperty.FieldProperty  
> object at 0x27537d0>

> test.number = 20  # this is ok

This overwrites the field property, as 'test' is your class, you  
called the instance 'test_class'.

test_class.number = 'asdf' results in the exception you expect.

Yours sincerely,
-- 
Michael Howitz · mh at gocept.com · software developer
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 8 · fax +49 345 1229889 1
Zope and Plone consulting and development



More information about the Zope3-users mailing list