diff --git a/CHANGES.rst b/CHANGES.rst index 1dcd3fa9..66b22944 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog 6.2 (unreleased) ---------------- +- Avoid error in search when the parameter received by ``IndexQuery`` is a ``record``. + (`#3007 `_) + - Refactored and improved ZMI templates (`#128 `_) diff --git a/src/Products/ZCatalog/query.py b/src/Products/ZCatalog/query.py index f7e5f949..19fef9e2 100644 --- a/src/Products/ZCatalog/query.py +++ b/src/Products/ZCatalog/query.py @@ -11,6 +11,9 @@ # ############################################################################## +from ZPublisher.HTTPRequest import record + + _marker = object() @@ -65,7 +68,7 @@ def __init__(self, request, iid, options=(), operators=('or', 'and'), param = request[iid] keys = None - if isinstance(param, dict): + if isinstance(param, (dict, record)): # query is a dictionary containing all parameters query = param.get('query', ()) if isinstance(query, (tuple, list)): diff --git a/src/Products/ZCatalog/tests/test_query.py b/src/Products/ZCatalog/tests/test_query.py index 21b8431c..0054f86c 100644 --- a/src/Products/ZCatalog/tests/test_query.py +++ b/src/Products/ZCatalog/tests/test_query.py @@ -13,6 +13,8 @@ import unittest +from ZPublisher.HTTPRequest import record + class TestIndexQuery(unittest.TestCase): @@ -109,3 +111,14 @@ def test_operator_string_with_underscores(self): with self.assertRaises(ValueError): self._makeOne( request, 'extra_path', ('query', 'operator'), ('or', 'and')) + + def test_param_record(self): + path = record() + path.query = ['foo'] + path.level = 0 + path.operator = 'and' + request = {'path': path} + parser = self._makeOne(request, 'path', ('query', 'level', 'operator')) + self.assertEqual(parser.get('keys'), ['foo']) + self.assertEqual(parser.get('level'), 0) + self.assertEqual(parser.get('operator'), 'and')