Re: [Zope3-Users] WrongContainedType
On Thu, Oct 09, 2008 at 08:42:21AM -0300, Tim Cook wrote: > I am having difficulty understanding this error. > > It occurs in the call: > ontObj.parentArchetype = ObjectRef(oid,u'openehr',u'ARCHETYPE') > > The first parameter for ObjectRef is declared in the schema as: > > refId = Object( > schema=IObjectId, > title = _(u'Id'), > description = _(u'Globally unique id of an object (of type > ObjectId), regardless of where it is stored.'), > required = True > ) > > If I print the parameter 'oid' it does correctly report: > 0x1b70210> > > the other two parameters for ObjectRef are declared as TextLines. > > The traceback is: > zope.schema.interfaces.WrongContainedType: [, []] Oh dear. That's one of the worst error messages I've seen. > What I do not understand is how to interpret the [, []] By reading the source code. Object field validation actually attempts to validate the schema (IObjectId in this case) of the object you're trying to store (the ObjectId object, in this case). If any of the fields cannot be validated during this nested validation, you get a WrongContainedType with the list of errors (one for each field). Apparently those errors have horrible __repr__s. That ought to be fixed. > I'm not passing a list nor is the schema using a list. > > I realize that this may be pretty basic but I am missing something in > reading the error. I'd put a breakpoint in zope.schema._field, specifically, in Object._validate, and try to see what's wrong by single-stepping. Marius Gedminas -- We're sysadmins. To us, data is a protocol-overhead. signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
Hi > Betreff: Re: [Zope3-Users] WrongContainedType [...] > By reading the source code. > > Object field validation actually attempts to validate the > schema (IObjectId in this case) of the object you're trying > to store (the ObjectId object, in this case). If any of the > fields cannot be validated during this nested validation, you > get a WrongContainedType with the list of errors (one for each field). I whould be really happy if we could set a flag in the Object field which whould force to avoid the storing object validation based on the given schema. What do you think about a validateSchema=True/False option or something like that? Regards Roger Ineichen ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
On Fri, 2008-10-10 at 11:07 +0200, Roger Ineichen wrote: > What do you think about a validateSchema=True/False option or something > like that? Maybe it's just a requirement to fix the code? The code at around line 466 in _field.py says errors = _validate_fields(self.schema, value) if errors: raise WrongContainedType(errors) errors is an empty list so should the if statement just be a test to see if the list is not empty? Cheers, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
Hi Tim > Betreff: Re: [Zope3-Users] WrongContainedType > > On Fri, 2008-10-10 at 11:07 +0200, Roger Ineichen wrote: > > > What do you think about a validateSchema=True/False option or > > something like that? > > Maybe it's just a requirement to fix the code? > > The code at around line 466 in _field.py says > errors = _validate_fields(self.schema, value) > if errors: > raise WrongContainedType(errors) > > errors is an empty list so should the if statement just be a > test to see if the list is not empty? I guess not, normaly such an error has an empty representation and the list is not empty. Try to do errors[0] or type(errors[0]) and you probably see something. If not I'm confused Regards Roger Ineichen > Cheers, > Tim > > > > > -- > Timothy Cook, MSc > Health Informatics Research & Development Services LinkedIn > Profile:http://www.linkedin.com/in/timothywaynecook > Skype ID == timothy.cook > ** > *You may get my Public GPG key from popular keyservers or * > *from this link http://timothywayne.cook.googlepages.com/home* > ** > ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
On Fri, 2008-10-10 at 12:38 -0300, Tim Cook wrote: > Maybe it's just a requirement to fix the code? > > The code at around line 466 in _field.py says > errors = _validate_fields(self.schema, value) > if errors: > raise WrongContainedType(errors) > > errors is an empty list so should the if statement just be a test to see > if the list is not empty? Actually, the problem is that the second iteration of the check causes the first list not to be empty anymore. by adding the line: print 'Object schema validation errors=',errors before the if errors: line I get this output: Object schema validation errors= [] Object schema validation errors= [, []] So I'm not sure WHERE errors is being created as a list each pass. I tried setting it to None with an else: clause and that didn't fix it. I hope this can help someone track down the problem. For now I have just commented out the error condition: #if errors: #raise WrongContainedType(errors) Cheers, --Tim -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
On Fri, 2008-10-10 at 17:46 +0200, Roger Ineichen wrote: > I guess not, normaly such an error has an empty representation > and the list is not empty. Try to do errors[0] or type(errors[0]) > and you probably see something. > > If not I'm confused Well, I'm confused anyway, but that isn't difficult. ;-) After commenting the the if test on errors and the raise. With print 'Object schema validation errors=',type(errors[0]): I get: Object schema validation errors= Object schema validation errors= With print 'Object schema validation errors=',errors[0]: I get: just the string Object schema validation errors= printed on each line. With print 'Object schema validation errors=',errors: I get: Object schema validation errors= [] Object schema validation errors= [] Just to try to cover all bases. I uncommented the if test and the only print that changed was the one with just 'errors' (the last one above). It produces, as I said before: Object schema validation errors= [] Object schema validation errors= [, []] Chasing this down is definitely above my Python abilities. Cheers, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
Hi Tim > Betreff: Re: AW: [Zope3-Users] WrongContainedType > > On Fri, 2008-10-10 at 17:46 +0200, Roger Ineichen wrote: > > > I guess not, normaly such an error has an empty > representation and the > > list is not empty. Try to do errors[0] or type(errors[0]) and you > > probably see something. > > > > If not I'm confused > > Well, I'm confused anyway, but that isn't difficult. ;-) > > After commenting the the if test on errors and the raise. > > With print 'Object schema validation errors=',type(errors[0]): > I get: > Object schema validation errors= > > Object schema validation errors= > > > With print 'Object schema validation errors=',errors[0]: > I get: > just the string Object schema validation errors= printed on each line. > > With print 'Object schema validation errors=',errors: > I get: > Object schema validation errors= [] > Object schema validation errors= [] > > Just to try to cover all bases. I uncommented the if test > and the only print that changed was the one with just > 'errors' (the last one above). > It produces, as I said before: > > Object schema validation errors= [] > Object schema validation errors= [, []] > > Chasing this down is definitely above my Python abilities. 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? 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. Regards Roger Ineichen ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [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/oship/openehr/am/archetype/ontology/archetypeontology.py Interface: http://www.openehr.org/svn/ref_impl_python/TRUNK/oship/src/oship/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/oship/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 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/schema/fieldproperty.py", line 52, in __set__ field.validate(value) File "/home/tim/.buildout/eggs/zope.schema-3.4.0-py2.5.egg/zope/schema/_bootstrapfields.py", line 138, in validate self._validate(value) File "/home/tim/.buildout/eggs/zope.schema-3.4.0-py2.5.egg/zope/schema/_field.py", line 469, in _validate raise WrongContainedType(errors) zope.schema.interfaces.WrongContainedType: [, []] * In the builder code you can see that oid is an instance of ObjectID. That seems to work okay. ObjectRef has three attributes, the first an instance of ObjectId, the second two are TextLines. http://www.openehr.org/svn/ref_impl_python/TRUNK/oship/src/oship/openehr/rm/support/identification/objectref.py Interface: http://www.openehr.org/svn/ref_impl_python/TRUNK/oship/src/oship/openehr/rm/support/identification/interfaces/objectref.py The ObjectId class and interface are in the same package if you want to look at them. Thanks, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
On Fri, Oct 10, 2008 at 06:19:48PM +0200, Roger Ineichen wrote: > Hi Tim > > > Betreff: Re: AW: [Zope3-Users] WrongContainedType > > > > On Fri, 2008-10-10 at 17:46 +0200, Roger Ineichen wrote: > > > > > I guess not, normaly such an error has an empty > > representation and the > > > list is not empty. Try to do errors[0] or type(errors[0]) and you > > > probably see something. > > > > > > If not I'm confused > > > > Well, I'm confused anyway, but that isn't difficult. ;-) > > > > After commenting the the if test on errors and the raise. > > > > With print 'Object schema validation errors=',type(errors[0]): > > I get: > > Object schema validation errors= > > > > Object schema validation errors= > > > > > > With print 'Object schema validation errors=',errors[0]: > > I get: > > just the string Object schema validation errors= printed on each line. > > > > With print 'Object schema validation errors=',errors: > > I get: > > Object schema validation errors= [] > > Object schema validation errors= [] That's because RequiredMissing subclasses ValidationError, which defines def __repr__(self): return ' '.join(map(str, self.args)) That's bad code! No cookie! If you do print [RequiredMissing()] you will see [] which is not distinguishable from an empty list. Things to fix: * ValidationError's __repr__ should consider the corner case when self.args is empty and return, say, self.__doc__. * the piece of code that raises RequiredMissing should always supply some arguments (at the very least, the name of the field with the missing value) > 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? > > 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. That is the correct path to fixing Tim's problem, but I think we should fix Zope as well. Marius Gedminas -- I used to be an agnostic, but now I'm not so sure. signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
On Fri, 2008-10-10 at 14:01 -0300, Tim Cook wrote: > 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? Well, that isn't very helpful I just discovered that the svn servers will be down all weekend for upgrades. The code is mirrored on Launchpad and the openehr code where the core classes and interfaces are should be up to date since the last import was five hours ago. http://bazaar.launchpad.net/~vcs-imports/oship/trunk/files/126?file_id=oshipsrcoship-20080801142259-4s7gdkogcl0fvfo2-13 -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
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 > 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 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
On Fri, 2008-10-10 at 21:17 +0200, Roger Ineichen wrote: > 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. > Unfortuuately you are looking at older code (before I really began testing this section). The code that is failing is: oid = ObjectId(unicode(parsed_adl.archetype[1])) ontObj.parentArchetype = ObjectRef(oid,u'openehr',u'ARCHETYPE') where oid is an instance of ObjectId. Sorry that the servers are down right now and will be all weekend. > Also this doesn't work: ... > > > In the sample above just remove the else condition. > The object whould return an empty list as defined > in default anyway. > Okay. > 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. Thanks. This is so obvious now that you pointed it out. :-) I'll look around for more of these. Thanks and have a great weekend. I'll be busy Grokifying this application. Cheers, Tim -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
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 signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] WrongContainedType
Just to follow up on this issue. I have created a bug report on launchpad with a possible fix. However, I do not know for sure that this doesn't have other negative consequences. https://bugs.launchpad.net/zope3/+bug/301226 Cheers, Tim On Thu, 2008-10-09 at 18:08 -0700, Marius Gedminas wrote: > On Thu, Oct 09, 2008 at 08:42:21AM -0300, Tim Cook wrote: > > I am having difficulty understanding this error. > > > > It occurs in the call: > > ontObj.parentArchetype = ObjectRef(oid,u'openehr',u'ARCHETYPE') > > > > The first parameter for ObjectRef is declared in the schema as: > > > > refId = Object( > > schema=IObjectId, > > title = _(u'Id'), > > description = _(u'Globally unique id of an object (of type > > ObjectId), regardless of where it is stored.'), > > required = True > > ) > > > > If I print the parameter 'oid' it does correctly report: > > > 0x1b70210> > > > > the other two parameters for ObjectRef are declared as TextLines. > > > > The traceback is: > > zope.schema.interfaces.WrongContainedType: [, []] > > Oh dear. That's one of the worst error messages I've seen. > > > What I do not understand is how to interpret the [, []] > > By reading the source code. > > Object field validation actually attempts to validate the schema > (IObjectId in this case) of the object you're trying to store (the > ObjectId object, in this case). If any of the fields cannot be > validated during this nested validation, you get a WrongContainedType > with the list of errors (one for each field). > > Apparently those errors have horrible __repr__s. That ought to be > fixed. > > > I'm not passing a list nor is the schema using a list. > > > > I realize that this may be pretty basic but I am missing something in > > reading the error. > > I'd put a breakpoint in zope.schema._field, specifically, in > Object._validate, and try to see what's wrong by single-stepping. > > Marius Gedminas > ___ > Zope3-users mailing list > Zope3-users@zope.org > http://mail.zope.org/mailman/listinfo/zope3-users -- Timothy Cook, MSc Health Informatics Research & Development Services LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook Skype ID == timothy.cook ** *You may get my Public GPG key from popular keyservers or * *from this link http://timothywayne.cook.googlepages.com/home* ** <> signature.asc Description: This is a digitally signed message part ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users