[Zope3-Users] WrongContainedType

Roger Ineichen dev at projekt01.ch
Fri Oct 10 15:17:08 EDT 2008


Hi Tim


> Betreff: Re: AW: AW: [Zope3-Users] WrongContainedType
> 
> 
> Thanks for your help Roger,
> 
> On Fri, 2008-10-10 at 18:19 +0200, Roger Ineichen wrote:
> > The error (probably, not sure) means that the object you 
> like to store 
> > has a missing value. Can you check the schema of this 
> object and set 
> > required=False in all fields?
> > 
> 
> Did that in both schemas on my local copy and no change.
> I just did a new commit to the svn prior to this email. 
> 
> > If there is a problem, can you post the interface and class of this 
> > object as a sample? And probably the code which tries to store the 
> > object.
> 
> The code for these are quite verbose and will certainly 
> obscure the commentary so I hope it's okay that I post links 
> to the SVN within the comments?
> 
> The failing code is when building an ArchetypeOntology class:
> http://www.openehr.org/svn/ref_impl_python/TRUNK/oship/src/osh
> ip/openehr/am/archetype/ontology/archetypeontology.py 
> 
> Interface:
> http://www.openehr.org/svn/ref_impl_python/TRUNK/oship/src/osh
> ip/openehr/am/archetype/ontology/interfaces/archetypeontology.py 
> 
> The builder code for this is here:
> http://www.openehr.org/svn/ref_impl_python/TRUNK/oship/src/osh
> ip/atbldr/bldontolgy.py 
> 
> It is failing when I try to assign the the value for the 
> parentArchetype attribute.  Here's the traceback:
> 
> **************************************************************
> ***********************
> Traceback (most recent call last):
>   File "load_ar.py", line 182, in <module>
>     CreateAT()
>   File "/home/tim/oshipenv/oship/src/oship/atbldr/atbldr.py", 
> line 142, in CreateAT
>     bldArchetype(parsed_adl)
>   File "/home/tim/oshipenv/oship/src/oship/atbldr/atbldr.py", 
> line 175, in bldArchetype
>     ontology=bldOntology(parsed_adl)
>   File 
> "/home/tim/oshipenv/oship/src/oship/atbldr/bldontolgy.py", 
> line 47, in bldOntology
>     ontObj.parentArchetype = ObjectRef(oid,u'openehr',u'ARCHETYPE')
>   File
> "/home/tim/.buildout/eggs/zope.schema-3.4.0-py2.5.egg/zope/sch
ema/fieldproperty.py", line 52, in __set__
>     field.validate(value)
>   File
> "/home/tim/.buildout/eggs/zope.schema-3.4.0-py2.5.egg/zope/sch
ema/_bootstrapfields.py", line 138, in validate
>     self._validate(value)
>   File
> "/home/tim/.buildout/eggs/zope.schema-3.4.0-py2.5.egg/zope/sch
ema/_field.py", line 469, in _validate
>     raise WrongContainedType(errors)
> zope.schema.interfaces.WrongContainedType: [, []]
> **************************************************************
> ***********************

I do not fully understand what the codes does but this does not work:

ontObj.parentArchetype = ''

Because it will set an empty string but an IObjectRef is needed.
Thats' not valid, just let it be, don't set anything else then
an IObjectRef as value.

Also this doesn't work:

terminologiesAvailable=List(  
  title=_(u"Terminologies"),  
  description=_(u"List of terminologies in this ontology."),  
  required=True,  
  value_type=TextLine(),  
  default=[],  
  )

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 = []


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.

Regards
Roger Ineichen



More information about the Zope3-users mailing list