From 45d298833b5f3f7edc124a6beb29e120c476a35a Mon Sep 17 00:00:00 2001 From: Wesley Barroso Lopes Date: Tue, 8 Feb 2022 18:35:04 -0300 Subject: [PATCH] Avoid error in search when the parameter received by IndexQuery is a record (#130) When using record notation in URL parameters, for example: http://localhost:8080/Plone/@@search?end.query:record:list:date=2022-2-2+00%3A00%3A00&end.range:record=min On the Zope side, this parameter becomes a ZPublisher.HTTPRequest.record, not a dictionary. However, IndexQuery only expected the parameter to be a dictionary. When the parameter is a record and it is not considered when extracting the 'query' key, the error occurs: TypeError: unailshable type: 'record' in search. Now we consider that the parameter can be a record as well. --- CHANGES.rst | 3 ++- src/Products/ZCatalog/query.py | 5 ++++- src/Products/ZCatalog/tests/test_query.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index e0468785..4e932a6c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 5.4 (unreleased) ---------------- -- Nothing changed yet. +- Avoid error in search when the parameter received by ``IndexQuery`` is a ``record``. + (`plone/Products.CMFPlone#3007 `_) 5.3 (2021-01-29) 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 cc4e3066..09c68fa2 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): @@ -98,3 +100,14 @@ def test_options_string(self): self._makeOne, request, 'path', ('query', 'operator')) + + 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')