Commit 6e8a132a authored by Tres Seaver's avatar Tres Seaver

Collector #1832: UnIndex swallowed ConflictErrors (bare 'except:' is evil).

parent abbd78bf
...@@ -38,6 +38,8 @@ Zope Changes ...@@ -38,6 +38,8 @@ Zope Changes
Bugs Fixed Bugs Fixed
- Collector #1832: UnIndex swallowed ConflictErrors.
- Collector #1815: ZCTextIndex accepts (again) sequences of strings to - Collector #1815: ZCTextIndex accepts (again) sequences of strings to
be indexed. be indexed.
......
...@@ -24,6 +24,7 @@ from BTrees.IOBTree import IOBTree ...@@ -24,6 +24,7 @@ from BTrees.IOBTree import IOBTree
import BTrees.Length import BTrees.Length
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from ZODB.POSException import ConflictError
from zope.interface import implements from zope.interface import implements
from Products.PluginIndexes import PluggableIndex from Products.PluginIndexes import PluggableIndex
...@@ -169,6 +170,9 @@ class UnIndex(SimpleItem): ...@@ -169,6 +170,9 @@ class UnIndex(SimpleItem):
del self._index[entry] del self._index[entry]
self._length.change(-1) self._length.change(-1)
except ConflictError:
raise
except AttributeError: except AttributeError:
# index row is an int # index row is an int
del self._index[entry] del self._index[entry]
...@@ -209,9 +213,7 @@ class UnIndex(SimpleItem): ...@@ -209,9 +213,7 @@ class UnIndex(SimpleItem):
def index_object(self, documentId, obj, threshold=None): def index_object(self, documentId, obj, threshold=None):
""" wrapper to handle indexing of multiple attributes """ """ wrapper to handle indexing of multiple attributes """
# needed for backward compatibility fields = self.getIndexSourceNames()
try: fields = self.indexed_attrs
except: fields = [ self.id ]
res = 0 res = 0
for attr in fields: for attr in fields:
...@@ -235,6 +237,8 @@ class UnIndex(SimpleItem): ...@@ -235,6 +237,8 @@ class UnIndex(SimpleItem):
if datum is _marker: if datum is _marker:
try: try:
del self._unindex[documentId] del self._unindex[documentId]
except ConflictError:
raise
except: except:
LOG.error('Should not happen: oldDatum was there, now its not,' LOG.error('Should not happen: oldDatum was there, now its not,'
'for document with id %s' % documentId) 'for document with id %s' % documentId)
...@@ -279,6 +283,8 @@ class UnIndex(SimpleItem): ...@@ -279,6 +283,8 @@ class UnIndex(SimpleItem):
try: try:
del self._unindex[documentId] del self._unindex[documentId]
except ConflictError:
raise
except: except:
LOG.error('Attempt to unindex nonexistent document' LOG.error('Attempt to unindex nonexistent document'
' with id %s' % documentId) ' with id %s' % documentId)
...@@ -391,10 +397,8 @@ class UnIndex(SimpleItem): ...@@ -391,10 +397,8 @@ class UnIndex(SimpleItem):
def getIndexSourceNames(self): def getIndexSourceNames(self):
""" return sequence of indexed attributes """ """ return sequence of indexed attributes """
try: # BBB: older indexes didn't have 'indexed_attrs'
return self.indexed_attrs return getattr(self, 'indexed_attrs', [self.id])
except:
return [ self.id ]
def uniqueValues(self, name=None, withLengths=0): def uniqueValues(self, name=None, withLengths=0):
"""returns the unique values for name """returns the unique values for name
......
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#############################################################################
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
#############################################################################
""" Tests for common UnIndex features.
$Id$
"""
import unittest
class UnIndexTests(unittest.TestCase):
def _getTargetClass(self):
from Products.PluginIndexes.common.UnIndex import UnIndex
return UnIndex
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def _makeConflicted(self):
from ZODB.POSException import ConflictError
class Conflicted:
def __str__(self):
return 'Conflicted'
__repr__ = __str__
def __getattr__(self, id, default=object()):
raise ConflictError, 'testing'
return Conflicted()
def test_empty(self):
unindex = self._makeOne(id='empty')
self.assertEqual(unindex.indexed_attrs, ['empty'])
def test_removeForwardIndexEntry_with_ConflictError(self):
from ZODB.POSException import ConflictError
unindex = self._makeOne(id='conflicted')
unindex._index['conflicts'] = self._makeConflicted()
self.assertRaises(ConflictError, unindex.removeForwardIndexEntry,
'conflicts', 42)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UnIndexTests))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
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