[Zope3-checkins] SVN: Zope3/trunk/ We can have indexes whose values
are determined by callable methods.
Adam Groszer
adamg at fw.hu
Mon Nov 20 07:22:03 EST 2006
Log message for revision 71200:
We can have indexes whose values are determined by callable methods.
Raising an exception in the method should not be silently ignored
That would cause index corruption -- the index would be out of sync
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/catalog/attribute.py
U Zope3/trunk/src/zope/app/catalog/tests.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2006-11-20 11:03:29 UTC (rev 71199)
+++ Zope3/trunk/doc/CHANGES.txt 2006-11-20 12:22:02 UTC (rev 71200)
@@ -260,6 +260,9 @@
- Fixed zope.index.field.index.FieldIndex. Unindex broke if the value
somehow dropped out of the forward index.
+ - We can have indexes whose values are determined by callable methods.
+ Raising an exception in the method should not be silently ignored
+ That would cause index corruption -- the index would be out of sync
Much thanks to everyone who contributed to this release:
Modified: Zope3/trunk/src/zope/app/catalog/attribute.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/attribute.py 2006-11-20 11:03:29 UTC (rev 71199)
+++ Zope3/trunk/src/zope/app/catalog/attribute.py 2006-11-20 12:22:02 UTC (rev 71200)
@@ -137,9 +137,7 @@
return None
if self.field_callable:
- try:
- value = value()
- except:
- return None
+ #do not eat the exception raised below
+ value = value()
return super(AttributeIndex, self).index_doc(docid, value)
Modified: Zope3/trunk/src/zope/app/catalog/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/tests.py 2006-11-20 11:03:29 UTC (rev 71199)
+++ Zope3/trunk/src/zope/app/catalog/tests.py 2006-11-20 12:22:02 UTC (rev 71200)
@@ -375,7 +375,49 @@
names = [x.author for x in res]
#joe must not be here anymore
self.assertEqual(len(names), 0)
+
+class stoopidCallable(object):
+ def __init__(self, **kw):
+ #leave the door open to not to set self.author
+ self.__dict__.update(kw)
+ def getAuthor(self):
+ return self.author
+
+class TestIndexRaisingValueGetter(unittest.TestCase):
+ """ """
+ def test_IndexRaisingValueGetter(self):
+ """We can have indexes whose values are determined by callable
+ methods.
+ Raising an exception in the method should not be silently ignored
+ That would cause index corruption -- the index would be out of sync"""
+ uidutil = IntIdsStub()
+ ztapi.provideUtility(IIntIds, uidutil)
+
+ catalog = Catalog()
+ index = FieldIndex('getAuthor', None, field_callable=True)
+ catalog['author'] = index
+
+ ob1 = stoopidCallable(author = "joe")
+ ob1id = uidutil.register(ob1)
+ catalog.index_doc(ob1id, ob1)
+
+ res = catalog.searchResults(author=('joe','joe'))
+ names = [x.author for x in res]
+ names.sort()
+ self.assertEqual(len(names), 1)
+ self.assertEqual(names, ['joe'])
+
+ ob2 = stoopidCallable() # no author here, will raise AttributeError
+ ob2id = uidutil.register(ob2)
+ try:
+ catalog.index_doc(ob2id, ob2)
+ self.fail("AttributeError exception should be raised")
+ except AttributeError:
+ #this is OK, we WANT to have the exception
+ pass
+
+
def test_suite():
from zope.testing import doctest
suite = unittest.TestSuite()
@@ -383,6 +425,7 @@
suite.addTest(unittest.makeSuite(TestEventSubscribers))
suite.addTest(unittest.makeSuite(TestIndexUpdating))
suite.addTest(unittest.makeSuite(TestCatalogBugs))
+ suite.addTest(unittest.makeSuite(TestIndexRaisingValueGetter))
suite.addTest(doctest.DocTestSuite('zope.app.catalog.attribute'))
suite.addTest(doctest.DocFileSuite(
'README.txt',
More information about the Zope3-Checkins
mailing list