ZCatalog Error in 2.4.0b2
Hi, I'm doing something simple: return catalog.searchResults(sort_on='dateofpublication') ...and getting something horrible: Error Type: TypeError Error Value: unsubscriptable object File /usr/local/zope/2.4.0b2_base/lib/python/Products/PythonScripts/PythonScript.py, line 362, in _exec (Object: latest_articles) (Info: ({'script': <PythonScript instance at 8cb0048>, 'context': <Folder instance at 85996a8>, 'container': <Folder instance at 85996a8>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 4, in latest_articles (Object: guarded_getitem) File /usr/local/zope/2.4.0b1_base/lib/python/Products/ZCatalog/Lazy.py, line 94, in __repr__ File /usr/local/zope/2.4.0b1_base/lib/python/Products/ZCatalog/Lazy.py, line 223, in __getitem__ TypeError: (see above) What's going on? cheers, Chris
I'm doing something simple:
return catalog.searchResults(sort_on='dateofpublication')
...and getting something horrible:
Error Type: TypeError Error Value: unsubscriptable object
Further scoping out this problem has expanded it: - this bug isn't limited to 2.4.0bx, it's also manifests at least in 2.3.2 and probably in 2.3.1+. ...and narrowed it: - the bug occurs when you sort on an index where more than one indexed item has the same value. For example, if: x=SimpleItem() y=SimpleItem() z=Simpleitem() x.fred=1 y.fred=1 z.fred=2 ...now if you have a FieldIndex called 'fred' and catalog this lot, you'll get the error when you do a search along the lines of: r = Catalog(sort_on='fred') However, if you changed it so y.fred=2 and z.fred=3, you wouldn't get any unexpected behaviour :-S It appears that IITreeSet objects don't like being subscripted. That sounds kindof weird, but then it doesn't look like IITreeSets should be appearing in that context anyhow... Help! Chris
The attached patch fixes the bug I was experiencing. I don't know why it needs to do what it does, but it was fairly obviously missing. Is it just me or are Catalog and ZCatalog quite messy? Chris --- Catalog.py.original Fri Jun 01 11:05:30 2001 +++ Catalog.py Sat Jul 21 11:53:32 2001 @@ -560,6 +560,7 @@ else: try: for k, intset in sort_index.items(): + if hasattr(intset, 'keys'): intset=intset.keys() append((k,LazyMap(self.__getitem__, intset))) except AttributeError: raise ValueError, (
participants (1)
-
Chris Withers