Skip to content

Commit

Permalink
Merge pull request #3 from wildcardcorp/master
Browse files Browse the repository at this point in the history
Check value is not None before inserting into forward index
  • Loading branch information
tseaver committed Apr 15, 2016
2 parents 81c3c53 + 43e8fb8 commit fd73627
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/zope/index/field/index.py
Expand Up @@ -55,18 +55,25 @@ def index_doc(self, docid, value):
"""See interface IInjection"""
rev_index = self._rev_index
if docid in rev_index:
if docid in self._fwd_index.get(value, ()):
# no need to index the doc, its already up to date
try:
if docid in self._fwd_index.get(value, ()):
# no need to index the doc, its already up to date
return
except TypeError:
return
# unindex doc if present
self.unindex_doc(docid)

# Insert into forward index.
set = self._fwd_index.get(value)
if set is None:
set = self.family.IF.TreeSet()
self._fwd_index[value] = set
set.insert(docid)
try:
# Insert into forward index.
set = self._fwd_index.get(value)
if set is None:
set = self.family.IF.TreeSet()
self._fwd_index[value] = set
set.insert(docid)
except TypeError:
# TypeError is caused by improper keys on the latest version of BTree
pass

# increment doc count
self._num_docs.change(1)
Expand Down
15 changes: 15 additions & 0 deletions src/zope/index/field/tests.py
Expand Up @@ -311,6 +311,21 @@ def test_sort_badlimit(self):
result = index.sort(c1, limit=0)
self.assertRaises(ValueError, list, result)

def test_insert_none_value_does_not_raise_typeerror(self):
index = self._makeOne()
index.index_doc(1, None)

def test_insert_none_value_to_update_does_not_raise_typeerror(self):
index = self._makeOne()
index.index_doc(1, 5)
index.index_doc(1, None)

def test_insert_none_value_does_not_insert_into_forward_index(self):
index = self._makeOne()
index.index_doc(1, None)
self.assertEquals(len(index._fwd_index), 0)
self.assertEquals(len(index._rev_index), 1)

def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.txt', optionflags=doctest.ELLIPSIS),
Expand Down

0 comments on commit fd73627

Please sign in to comment.