Skip to content

Commit

Permalink
Avoid error in search when the parameter received by IndexQuery is a …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
wesleybl committed Feb 8, 2022
1 parent f9ac405 commit 45d2988
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -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 <https://github.com/plone/Products.CMFPlone/issues/3007>`_)


5.3 (2021-01-29)
Expand Down
5 changes: 4 additions & 1 deletion src/Products/ZCatalog/query.py
Expand Up @@ -11,6 +11,9 @@
#
##############################################################################

from ZPublisher.HTTPRequest import record


_marker = object()


Expand Down Expand Up @@ -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)):
Expand Down
13 changes: 13 additions & 0 deletions src/Products/ZCatalog/tests/test_query.py
Expand Up @@ -13,6 +13,8 @@

import unittest

from ZPublisher.HTTPRequest import record


class TestIndexQuery(unittest.TestCase):

Expand Down Expand Up @@ -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')

0 comments on commit 45d2988

Please sign in to comment.