Odd behaviour with lexicons and ZCTextIndex
We have a site with the following structure: / `- foo |- lexicon `- bar (foo and bar are ZClasses) When I add the 'bar' under 'foo', and in 'bar's constructor, add a catalog to bar and a ZCTextIndex to the catalog with an external method[1], in 2.6.0 it works just fine, but with 2.6.1 I get the following error: Error Type: LookupError Error Value: Lexicon "lexicon" not found The end of the traceback looks like this: * Module Products.ZCatalog.ZCatalog, line 897, in addIndex * Module Products.ZCTextIndex.ZCTextIndex, line 78, in __init__ LookupError: Lexicon "lexicon" not found [1] the external method we use for adding ZCTextIndexes: def addZCTextIndex(context, id, field=''): extra = Extra() extra.index_type = 'Okapi BM25 Rank' extra.lexicon_id = 'lexicon' if field: extra.doc_attr = field if id: context.addIndex(id, 'ZCTextIndex', extra) -- paavo. "joskus voi tää meno käydä ahdistavaksi kun on täällä muodostunut tavaksi muuttaa jokaisen elämän arvo rahaksi"
Paavo Parkkinen wrote at 2003-7-9 13:56 +0300:
We have a site with the following structure:
/ `- foo |- lexicon `- bar
(foo and bar are ZClasses)
When I add the 'bar' under 'foo', and in 'bar's constructor, add a catalog to bar and a ZCTextIndex to the catalog with an external method[1], in 2.6.0 it works just fine, but with 2.6.1 I get the following error:
Error Type: LookupError Error Value: Lexicon "lexicon" not found
The end of the traceback looks like this:
* Module Products.ZCatalog.ZCatalog, line 897, in addIndex * Module Products.ZCTextIndex.ZCTextIndex, line 78, in __init__
LookupError: Lexicon "lexicon" not found
[1] the external method we use for adding ZCTextIndexes:
def addZCTextIndex(context, id, field=''): extra = Extra() extra.index_type = 'Okapi BM25 Rank' extra.lexicon_id = 'lexicon' if field: extra.doc_attr = field
if id: context.addIndex(id, 'ZCTextIndex', extra)
Is it possible that your "ZCatalog" is not yet acquisition wrapped when you call "addIndex"? Dieter
On ke, 09.07.2003 at 20:55 +0200, Dieter Maurer wrote:
Is it possible that your "ZCatalog" is not yet acquisition wrapped when you call "addIndex"?
As I said, the exact same classes work on 2.6.0. I guess it could be, that in 2.6.1 they aren't yet aquisition wrapped, but I'm really not familiar enough with the inner workings of zope to tell. Is there any way I can test that? -- paavo. "joskus voi tää meno käydä ahdistavaksi kun on täällä muodostunut tavaksi muuttaa jokaisen elämän arvo rahaksi"
On to, 10.07.2003 at 06:22 +0300, Paavo Parkkinen wrote:
On ke, 09.07.2003 at 20:55 +0200, Dieter Maurer wrote:
Is it possible that your "ZCatalog" is not yet acquisition wrapped when you call "addIndex"?
As I said, the exact same classes work on 2.6.0. I guess it could be, that in 2.6.1 they aren't yet aquisition wrapped, but I'm really not familiar enough with the inner workings of zope to tell. Is there any way I can test that?
I just realized, that we use aquisition in other parts of the same contructor (the external methods, for example, plus other things), so I'm pretty certain, that it is aquisition wrapped when trying to add the index. -- paavo. "joskus voi tää meno käydä ahdistavaksi kun on täällä muodostunut tavaksi muuttaa jokaisen elämän arvo rahaksi"
On ke, 09.07.2003 at 20:55 +0200, Dieter Maurer wrote:
Is it possible that your "ZCatalog" is not yet acquisition wrapped when you call "addIndex"?
I finally had some time to take a look at this problem a little deeper, and it seems that the ZCatalog is not aquisition wrapped when calling 'addIndex'. This problem seems to be fixed in 2.7.0-a1. Here's a patch for the 2.6.1 users: --- ZCatalog.py.orig 2003-07-21 19:31:55.000000000 +0300 +++ ZCatalog.py 2003-07-21 19:45:21.000000000 +0300 @@ -894,7 +894,7 @@ # for new index types is to use an "extra" record. if 'extra' in base.__init__.func_code.co_varnames: - index = base(name, extra=extra, caller=aq_base(self)) + index = base(name, extra=extra, caller=self) else: index = base(name, aq_base(self)) -- paavo. "joskus voi tää meno käydä ahdistavaksi kun on täällä muodostunut tavaksi muuttaa jokaisen elämän arvo rahaksi"
Paavo Parkkinen wrote at 2003-7-21 19:47 +0300:
On ke, 09.07.2003 at 20:55 +0200, Dieter Maurer wrote:
Is it possible that your "ZCatalog" is not yet acquisition wrapped when you call "addIndex"?
I finally had some time to take a look at this problem a little deeper, and it seems that the ZCatalog is not aquisition wrapped when calling 'addIndex'. This problem seems to be fixed in 2.7.0-a1.
Here's a patch for the 2.6.1 users:
--- ZCatalog.py.orig 2003-07-21 19:31:55.000000000 +0300 +++ ZCatalog.py 2003-07-21 19:45:21.000000000 +0300 @@ -894,7 +894,7 @@ # for new index types is to use an "extra" record.
if 'extra' in base.__init__.func_code.co_varnames: - index = base(name, extra=extra, caller=aq_base(self)) + index = base(name, extra=extra, caller=self) else: index = base(name, aq_base(self))
The same problem is also in the "else:" clause. There is another bug in this code (which is horrible under all accounts): "co_varnames" is used as if it were the sequence of arguments. However, as the name clearly suggests: it is the sequence of (all) variables in the code objects. This includes arguments and local variables. If "base" does not have an "extra" argument but a local variable called "extra", the code above will fail with a "TypeError: unexpected keyword argument 'extra'". This error is not very likely but when it happens deep Python Zen is necessary to understand what happened. Dieter
participants (3)
-
Dieter Maurer -
Paavo Parkkinen -
Paavo Parkkinen