Skip to content

Commit

Permalink
Merge 98e0ff7 into 2a21568
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Apr 22, 2018
2 parents 2a21568 + 98e0ff7 commit 7958ce9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
4.2 (unreleased)
----------------

- Nothing changed yet.
- Fix a TypeError on Python 3 when trying to lookup in an OOBTree
a value for a key that has an invalid type


4.1 (2018-03-06)
Expand Down
29 changes: 29 additions & 0 deletions src/Products/PluginIndexes/tests/test_unindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from OFS.SimpleItem import SimpleItem
from Testing.makerequest import makerequest

from Products.ZCatalog.query import IndexQuery


class TestUnIndex(unittest.TestCase):

Expand Down Expand Up @@ -164,3 +166,30 @@ class Dummy(object):
# clear changes the index
index.clear()
self.assertEqual(index.getCounter(), 3)

def test_no_type_error(self):
''' Check that on Python 3.6 we do not get a TypeError when trying
to query an index with a key that has an invalid type
'''
index = self._makeOne('counter')

class Dummy(object):
id = 1
counter = 'test'

obj = Dummy()
index.index_object(obj.id, obj)

# With the right query we can find the object
query = IndexQuery({'counter': 'test'}, 'counter')
res = index.query_index(query)
self.assertListEqual(list(res), [1])

# If the type is not the expected one we cannot
query = IndexQuery({'counter': None}, 'counter')
res = index.query_index(query)
self.assertListEqual(list(res), [])

query = IndexQuery({'counter': 42}, 'counter')
res = index.query_index(query)
self.assertListEqual(list(res), [])
6 changes: 5 additions & 1 deletion src/Products/PluginIndexes/unindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ def query_index(self, record, resultset=None):
# other object. BTrees 4.0+ will throw a TypeError
# "object has default comparison".
continue
s = index.get(k, None)
try:
s = index.get(k, None)
except TypeError:
# key is not valid for this Btree so the value is None
s = None
# If None, try to bail early
if s is None:
if operator == 'or':
Expand Down

0 comments on commit 7958ce9

Please sign in to comment.