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

Daniel Nouri daniel.nouri at gmail.com
Wed Mar 15 06:53:27 EST 2006


On Mon, 2006-03-13 at 17:13 +0000, Christian Lück wrote:
> 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).

I don't have Stephan's book around right now.  But I'm using the Object
field just as you suggest.  But that doesn't work.  The error is the
same as described above.  I just wanted to reproduce it in the
interactive interpreter.

Thanks
Daniel






More information about the Zope3-users mailing list