[Zope3-Users] Weird error for a certain named attribute

Maken Seteva crapkonto at gmail.com
Tue Oct 23 08:11:17 EDT 2007


Hello Tom,

Thank you very much, your pointers helped me to solving it.

Tags was indexed with a TextIndex using my adapter FooTags which had  
a function
to join the list:

      def getSearchableList(self):
          s = ' '.join(self.context.tags)
          #if s == '':
          #    return None
          return s

The part that is commented out was the cause of my error. Returning a  
None when the
list is empty will of course cause an error of  "iteration over non- 
sequence" when indexing.

Btw, is there an already existing way to index a field with a list of  
strings so you can do a
search on a particular element in the list? It's a little cumbrsome  
writing an adapter for each
field that has a list of strings to join them as one string (if this  
is even a good solution at all, I'm
not sure).

Regards
Steva



On Oct 22, 2007, at 11:20 PM, Tom Dossis wrote:

> Hi Maken,
>
> From the stack trace it looks like the problem is related to  
> cataloging your object.
>
> From this point, there's a couple things to look at.
>
> 1. How are you cataloging IFoo?  How did you set up the catalog?
>
> 2. Enter a break point or print statement in lexicon.py to see  
> what's happening in the method sourceToWordIds just after the call  
> to _text2list,
>   e.g. print repr(text), repr(last).
> I'd be interested to see what these value's are.  I can't see how  
> it's failing, but since it appears so, maybe there's a bug in  
> _text2list.
>
> BTW, just to explain my original suggestion...  When you use  
> EditForm, you have a Foo object, which means it's __init__ method  
> has been called and the tag attribute has been set to  
> PersistentList.  However in the case of AddForm, there is no Foo  
> instance from which to bind the widgets to.  In this case you may  
> need to explicitly say something about the tag field default value,  
> because AddForm will need to use this value.
>
> -Tom
>
> On 22/10/2007, at 9:14 PM, Maken Seteva wrote:
>
>>
>> On Oct 18, 2007, at 10:54 PM, Tom Dossis wrote:
>>
>>>
>>> On 18/10/2007, at 11:58 PM, Maken Seteva wrote:
>>>
>>>> Hello,
>>>> I have a very strange error that I cannot understand. I get an  
>>>> error for one of my attribute
>>>> only when it is named a certain name!  It seems like there is an  
>>>> old implementation of
>>>> it that is haunting in the background, how is this possible?
>>>>
>>>> This cursed name is called "tags". This attribute is a list of  
>>>> TextLine. I get the error when I
>>>> don't add anything to the list in the adding view:
>>>>
>>>> "TypeError: iteration over non-sequence"
>>>>
>>>>
>>>> However, if I rename the attribute to "wehoo" or really,  
>>>> anything else, I don't get the TypeError and
>>>> I can add my content object successfully (with an empty list for  
>>>> wehoo). Here's my component:
>>>>
>>>> class IFoo(IContained):
>>>> 	#...
>>>>      tags = List(
>>>>          title=_(u'Tags'),
>>>>          description=_(u'A list of keywords'),
>>>>          max_length=10,
>>>>          value_type=TextLine(title=_(u'Tag')),
>>>>          unique=True
>>>>          )
>>>> 	#...
>>>>
>>>>
>>>> class Foo(Persistent):
>>>> 	implements(IFoo)
>>>> 	__name__ = __parent__ = None
>>>> 	def __init__(self):
>>>> 		#...
>>>> 		self.tags = PersistentList()
>>>> 		#...
>>>>
>>>> No custom widgets used for this field...
>>>>
>>>> I tried deleting all .pyc-files and deleting all old Foo  
>>>> objects, and the site i run for testing followed by
>>>> restarting the server. But adding new Foo objects still don't  
>>>> work. (But renaming tags to anything else
>>>> and then trying again will succeed).
>>>>
>>>> Any ideas?
>>>
>>> Add: default=[] to your IFoo schema.
>>>
>>> -Tom
>>>
>>
>> Hi Tom,
>> I did just that and I still get the TypeError. It is kind of  
>> confusing in how to allow an empty list
>> for a schema field. If required=True for the list, why doesn't it  
>> complain when I don't add
>> anything to the list in the form? Btw, I don't want this field to  
>> be required, but i just noticed
>> this oddity(?) when trying different settings.
>>
>> This was the last setting for the field I used (and it failed):
>>
>>
>>      tags = List(
>>          title=_(u'Tags'),
>>          description=_(u'A list of keywords'),
>>          max_length=10,
>>          required=False,
>>          default=[],
>>          value_type=TextLine(title=_(u'Tag')),
>>          unique=True
>>          )
>>
>>
>> I printed out the data dict in my AddForm's create function to
>> see what the value for tags was when no tags are added in the  
>> form.. it is really an empty list..
>>
>>
>> Here's my full traceback I get after pressing "Add" button in my  
>> adding view for Foo:
>>
>> 2007-10-22T12:31:13 ERROR SiteError http://localhost:8080/Site/ 
>> foos/+/mytest.addpage.Foo%3D
>> Traceback (most recent call last):
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/publisher/ 
>> publish.py", line 133, in publish
>>     result = publication.callObject(request, obj)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/ 
>> publication/zopepublication.py", line 161, in callObject
>>     return mapply(ob, request.getPositionalArguments(), request)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/publisher/ 
>> publish.py", line 108, in mapply
>>     return debug_call(obj, args)
>>    - __traceback_info__: <security proxied  
>> zope.app.publisher.browser.viewmeta.FooAddForm instance at 0x3fa3c30>
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/publisher/ 
>> publish.py", line 114, in debug_call
>>     return obj(*args)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/formlib/ 
>> form.py", line 769, in __call__
>>     self.update()
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/formlib/ 
>> form.py", line 750, in update
>>     result = action.success(data)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/formlib/ 
>> form.py", line 594, in success
>>     return self.success_handler(self.form, self, data)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/formlib/ 
>> form.py", line 861, in handle_add
>>     self.createAndAdd(data)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/formlib/ 
>> form.py", line 868, in createAndAdd
>>     return self.add(ob)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/formlib/ 
>> form.py", line 877, in add
>>     ob = self.context.add(object)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/container/ 
>> browser/adding.py", line 72, in add
>>     container[name] = content
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/container/ 
>> sample.py", line 86, in __setitem__
>>     setitem(self, self.__data.__setitem__, key, object)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/container/ 
>> contained.py", line 593, in setitem
>>     notify(event)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/event/ 
>> __init__.py", line 23, in notify
>>     subscriber(event)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> event.py", line 26, in dispatch
>>     for ignored in zope.component.subscribers(event, None):
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> _api.py", line 130, in subscribers
>>     return sitemanager.subscribers(objects, interface)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> registry.py", line 290, in subscribers
>>     return self.adapters.subscribers(objects, provided)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/interface/ 
>> adapter.py", line 535, in subscribers
>>     subscription(*objects)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> event.py", line 33, in objectEventNotify
>>     adapters = zope.component.subscribers((event.object, event),  
>> None)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> _api.py", line 130, in subscribers
>>     return sitemanager.subscribers(objects, interface)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> registry.py", line 290, in subscribers
>>     return self.adapters.subscribers(objects, provided)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/interface/ 
>> adapter.py", line 535, in subscribers
>>     subscription(*objects)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/intid/ 
>> __init__.py", line 169, in addIntIdSubscriber
>>     notify(IntIdAddedEvent(ob, event))
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/event/ 
>> __init__.py", line 23, in notify
>>     subscriber(event)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> event.py", line 26, in dispatch
>>     for ignored in zope.component.subscribers(event, None):
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> _api.py", line 130, in subscribers
>>     return sitemanager.subscribers(objects, interface)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/component/ 
>> registry.py", line 290, in subscribers
>>     return self.adapters.subscribers(objects, provided)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/interface/ 
>> adapter.py", line 535, in subscribers
>>     subscription(*objects)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/catalog/ 
>> catalog.py", line 153, in indexDocSubscriber
>>     cat.index_doc(id, ob)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/catalog/ 
>> catalog.py", line 62, in index_doc
>>     index.index_doc(docid, texts)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/app/catalog/ 
>> attribute.py", line 144, in index_doc
>>     return super(AttributeIndex, self).index_doc(docid, value)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/index/text/ 
>> textindex.py", line 45, in index_doc
>>     self.index.index_doc(docid, text)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/index/text/ 
>> okapiindex.py", line 225, in index_doc
>>     count = BaseIndex.index_doc(self, docid, text)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/index/text/ 
>> baseindex.py", line 95, in index_doc
>>     wids = self._lexicon.sourceToWordIds(text)
>>   File "/home/mset/local/Zope-3.3.1/lib/python/zope/index/text/ 
>> lexicon.py", line 66, in sourceToWordIds
>>     for t in last:
>> TypeError: iteration over non-sequence
>>
>>
>> Thanks in advance
>>
>



More information about the Zope3-users mailing list