Commit 61bd94e9 authored by Zachery Bir's avatar Zachery Bir

carried forward from Zope-2_8-branch

parent 257ac8fa
...@@ -26,6 +26,8 @@ from BTrees.OIBTree import OIBTree ...@@ -26,6 +26,8 @@ from BTrees.OIBTree import OIBTree
from DateTime.DateTime import DateTime from DateTime.DateTime import DateTime
from Globals import DTMLFile from Globals import DTMLFile
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
from ZODB.POSException import ConflictError
from zLOG import LOG, ERROR
from zope.interface import implements from zope.interface import implements
from Products.PluginIndexes.common import safe_callable from Products.PluginIndexes.common import safe_callable
...@@ -135,6 +137,16 @@ class DateIndex(UnIndex, PropertyManager): ...@@ -135,6 +137,16 @@ class DateIndex(UnIndex, PropertyManager):
if ConvertedDate != oldConvertedDate: if ConvertedDate != oldConvertedDate:
if oldConvertedDate is not _marker: if oldConvertedDate is not _marker:
self.removeForwardIndexEntry(oldConvertedDate, documentId) self.removeForwardIndexEntry(oldConvertedDate, documentId)
if ConvertedDate is _marker:
try:
del self._unindex[documentId]
except ConflictError:
raise
except:
LOG('UnIndex', ERROR,
("Should not happen: ConvertedDate was there,"
" now it's not, for document with id %s" %
documentId))
if ConvertedDate is not _marker: if ConvertedDate is not _marker:
self.insertForwardIndexEntry( ConvertedDate, documentId ) self.insertForwardIndexEntry( ConvertedDate, documentId )
......
...@@ -239,6 +239,20 @@ class DI_Tests(unittest.TestCase): ...@@ -239,6 +239,20 @@ class DI_Tests(unittest.TestCase):
val = (((yr * 12 + mo) * 31 + dy) * 24 + hr) * 60 + mn val = (((yr * 12 + mo) * 31 + dy) * 24 + hr) * 60 + mn
self.failUnlessEqual(self._index.getEntryForObject(k), val) self.failUnlessEqual(self._index.getEntryForObject(k), val)
def test_removal(self):
""" DateIndex would hand back spurious entries when used as a
sort_index, because it previously was not removing entries
from the _unindex when indexing an object with a value of
None. The catalog consults a sort_index's
documentToKeyMap() to build the brains.
"""
values = self._values
index = self._index
self._populateIndex()
self._checkApply(self._int_req, [values[7]])
index.index_object(7, None)
self.failIf(7 in index.documentToKeyMap().keys())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment