[Zope3-Users] IField in Object(Field): RequiredMissing

Christian Lück christian.lueck at ruhr-uni-bochum.de
Mon Mar 13 12:13:01 EST 2006


Daniel Nouri wrote:
> Not sure I'm using the Object field right, but this seems odd:
> 
>         >>> from zope.schema import Field, Object
>         >>> from zope.schema.interfaces import IField
>         >>> field = Object(IField)
>         >>> field.validate(Field())
>         Traceback (most recent call last):
>           File "<stdin>", line 1, in ?
>           File
>         "/home/daniel/lib/Zope-3.2.0/lib/python/zope/schema/_bootstrapfields.py", line 138, in validate
>             self._validate(value)
>           File
>         "/home/daniel/lib/Zope-3.2.0/lib/python/zope/schema/_field.py",
>         line 418, in _validate
>             raise WrongContainedType(errors)
>         zope.schema.interfaces.WrongContainedType: [, ]
>         
> The error message is not really helpful.  Turns out that the given error
> is a RequiredMissing error and it's missing the value of 'default' on
> the field.
> 
> Am I doing something wrong or is the Object field not behaving as it
> should?
> 

It does as it should. Use it this way:

from zope.interface import Interface
from zope.schema import Object

class IFoo(Interface):
	#blabla

class IFooture(Interface):
	bar = Object(IFoo, title=u"blabla")
	# you can also give the IFoo-Interface as a keyword:
	barbar = Object(schema=IFoo, title=u"blabla from barbar")

There is a nice and helpfull example in ++apidoc++: Book --> Widgets and
Forms --> Advanced Widgets
Please also refer to srichter's book, chapter 8.3 (p. 54).

Regards,
Christian


More information about the Zope3-users mailing list