[Zope3-checkins] SVN: Zope3/trunk/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:51 EST 2006


Log message for revision 71192:
  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/trunk/src/zope/app/catalog/attribute.py
  U   Zope3/trunk/src/zope/app/catalog/tests.py

-=-
Modified: Zope3/trunk/src/zope/app/catalog/attribute.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/attribute.py	2006-11-20 09:40:24 UTC (rev 71191)
+++ Zope3/trunk/src/zope/app/catalog/attribute.py	2006-11-20 09:40:50 UTC (rev 71192)
@@ -132,6 +132,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/trunk/src/zope/app/catalog/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/tests.py	2006-11-20 09:40:24 UTC (rev 71191)
+++ Zope3/trunk/src/zope/app/catalog/tests.py	2006-11-20 09:40:50 UTC (rev 71192)
@@ -31,6 +31,8 @@
 from zope.index.interfaces import IInjection, IIndexSearch
 from zope.app.catalog.interfaces import ICatalog
 from zope.app.catalog.catalog import Catalog
+from zope.app.catalog.attribute import AttributeIndex
+from zope.app.catalog.field import FieldIndex
 
 class ReferenceStub:
     def __init__(self, obj):
@@ -342,17 +344,45 @@
         index = self.cat['name']
         names = sorted([ob.__name__ for i, ob in index.doc.items()])
         self.assertEqual(names, [u'folder1_1', u'folder1_1_1', u'folder1_1_2'])
+
+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(TestIndexUpdating))
+    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