[Zope3-Users] schema.List validation does not accept PersistentList

Alek Kowalczyk thealx at poczta.onet.pl
Thu Jul 19 07:42:31 EDT 2007


Hi,

I have a schema with the List field defined:

from zope.interface import Interface
from zope.schema import List, TextLine
class IMyObject(Interface):
   myList = List(title=u'mylist', value_type=TextLine(title=u'item'))

Then I implement this using field property. 
Then in constructor I assign a Persistent List to this field.

from zope.schema.fieldproperty import FieldProperty
class MyObject(Persistent, Contained):
   myList = FieldProperty(IMyObject['myList'])
   def __init__(self):
      self.myList = PersistentList()

and I get the following stack trace. 
Is it intended behavior that schema.List doesn't accept PersistentList? 
How do you work around that? I don't want to abadon field validation using
FieldProperty.

  File "C:\Python24\Lib\site-packages\zope\schema\fieldproperty.py", line 52, in
__set__
    field.validate(value)
  File "C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py", line
138, in validate
    self._validate(value)
  File "C:\Python24\Lib\site-packages\zope\schema\_field.py", line 358, in _validate
    super(AbstractCollection, self)._validate(value)
  File "C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py", line
263, in _validate
    super(MinMaxLen, self)._validate(value)
  File "C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py", line
201, in _validate
    super(Iterable, self)._validate(value)
  File "C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py", line
189, in _validate
    super(Container, self)._validate(value)
  File "C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py", line
165, in _validate
    raise WrongType(value, self._type)
WrongType: ([], <type 'list'>)




More information about the Zope3-users mailing list