[Zope3-checkins] SVN: Zope3/branches/3.2/src/zope/app/catalog/ I
found that z.a.catalog, AttributeIndex failed to remove the previous
Adam Groszer
adamg at fw.hu
Mon Nov 20 04:40:04 EST 2006
Log message for revision 71190:
I found that z.a.catalog, AttributeIndex failed to remove the previous
value/object from the index IF the NEW value is None.
Changed:
U Zope3/branches/3.2/src/zope/app/catalog/attribute.py
U Zope3/branches/3.2/src/zope/app/catalog/tests.py
-=-
Modified: Zope3/branches/3.2/src/zope/app/catalog/attribute.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/catalog/attribute.py 2006-11-20 09:35:19 UTC (rev 71189)
+++ Zope3/branches/3.2/src/zope/app/catalog/attribute.py 2006-11-20 09:40:03 UTC (rev 71190)
@@ -131,6 +131,8 @@
value = getattr(object, self.field_name, None)
if value is None:
+ #unindex the previous value!
+ super(AttributeIndex, self).unindex_doc(docid)
return None
if self.field_callable:
Modified: Zope3/branches/3.2/src/zope/app/catalog/tests.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/catalog/tests.py 2006-11-20 09:35:19 UTC (rev 71189)
+++ Zope3/branches/3.2/src/zope/app/catalog/tests.py 2006-11-20 09:40:03 UTC (rev 71190)
@@ -33,6 +33,8 @@
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.catalog import Catalog
from zope.app import zapi
+from zope.app.catalog.attribute import AttributeIndex
+from zope.app.catalog.field import FieldIndex
class ReferenceStub:
def __init__(self, obj):
@@ -283,12 +285,43 @@
self.assertEqual(self.cat.unregs, [id])
self.assertEqual(self.cat.regs, [])
+class TestCatalogBugs(unittest.TestCase):
+ """I found that z.a.catalog, AttributeIndex failed to remove the previous
+ value/object from the index IF the NEW value is None.
+ """
+
+ def test_updateIndexWithNone(self):
+ uidutil = IntIdsStub()
+ ztapi.provideUtility(IIntIds, uidutil)
+
+ catalog = Catalog()
+ index = FieldIndex('author', None)
+ catalog['author'] = index
+
+ ob1 = stoopid(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'])
+
+ ob1.author = None
+ catalog.index_doc(ob1id, ob1)
+
+ res = catalog.searchResults(author=('joe','joe'))
+ names = [x.author for x in res]
+ #joe must not be here anymore
+ self.assertEqual(len(names), 0)
def test_suite():
from zope.testing import doctest
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
suite.addTest(unittest.makeSuite(TestEventSubscribers))
+ suite.addTest(unittest.makeSuite(TestCatalogBugs))
suite.addTest(doctest.DocTestSuite('zope.app.catalog.attribute'))
suite.addTest(doctest.DocFileSuite(
'README.txt',
More information about the Zope3-Checkins
mailing list