[Zope3-Users] WrongContainedType

Marius Gedminas marius at gedmin.as
Fri Oct 10 17:53:22 EDT 2008


On Fri, Oct 10, 2008 at 09:17:08PM +0200, Roger Ineichen wrote:
> Also this doesn't work:
> 
> terminologiesAvailable=List(  
>   title=_(u"Terminologies"),  
>   description=_(u"List of terminologies in this ontology."),  
>   required=True,  
>   value_type=TextLine(),  
>   default=[],  

Ouch, careful!  If you have a mutable object as the default value of a
field, it's really easy to accidentally end up with multiple objects
sharing the same value object.

>   )
> 
> if 'terminologies_available' in sections:  
>     ontObj.terminologiesAvailable =
> parsed_adl.ontology['terminologies_available'][0]  
> else:  
>      ontObj.terminologiesAvailable = []  
> 
> Here you're trying to set an empty list as value.
> The schema says required=True and that's not the case with 
> ontObj.terminologiesAvailable = []

It's interesting, but I always thought required=True meant the field
couldn't be None, and [] is not None.  Then again I never quite
completely understood all the corners of zope.schema.

> In the sample above just remove the else condition.
> The object whould return an empty list as defined
> in default anyway.
> 
> I hope I catched the right interfaces and didn't mess tings up.
> Is there another terminologiesAvailable attr defined in another interface?
> 
> btw,
> I really dislike this invalid schema definitions. With
> invalid I mean the default value is not a vaild value
> if ou try to store them. 

> because of:
> 
> required=True
> default=[]
> 
> This is a combination which is not valid and it's not possible 
> to store the default value again.

Marius Gedminas
-- 
World domination.  Fast.
                -- Linus Torvalds
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20081010/7913e3bc/attachment.bin 


More information about the Zope3-users mailing list