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

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 6a220c6 commit 11df7ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,9 @@ Changelog
6.2 (unreleased)
----------------

- Avoid error in search when the parameter received by ``IndexQuery`` is a ``record``.
(`#3007 <https://github.com/plone/Products.CMFPlone/issues/3007>`_)

- Refactored and improved ZMI templates
(`#128 <https://github.com/zopefoundation/Products.ZCatalog/pull/128>`_)

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 @@ -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')

0 comments on commit 11df7ae

Please sign in to comment.