Skip to content

Add test case for failure in search call #1898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2025
Merged

Add test case for failure in search call #1898

merged 3 commits into from
Jun 16, 2025

Conversation

tiberiuichim
Copy link
Contributor

@tiberiuichim tiberiuichim commented Mar 21, 2025

For some reason the @search endpoint fails when passed with expanders like:

@search?expand=navigation,actions&expand.navigation.depth=2

I'm not sure how who's trying to use this URL and for what purpose, I saw it as an error in our logs.


📚 Documentation preview 📚: https://plonerestapi--1898.org.readthedocs.build/

@mister-roboto
Copy link

@tiberiuichim thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@tiberiuichim
Copy link
Contributor Author

Tests fail with:

Error in test test_expand (plone.restapi.tests.test_search_utils.TestUnflattenDottedDict)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
    yield
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 676, in run
    self._callTestMethod(testMethod)
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
    method()
  File "/home/runner/work/plone.restapi/plone.restapi/src/plone/restapi/tests/test_search_utils.py", line 31, in test_expand
    unflatten_dotted_dict(dct),
  File "/home/runner/work/plone.restapi/plone.restapi/src/plone/restapi/search/utils.py", line 35, in unflatten_dotted_dict
    inner = reduce(create_or_get, [result] + key_segments[:-1])
  File "/home/runner/work/plone.restapi/plone.restapi/src/plone/restapi/search/utils.py", line [28](https://github.com/plone/plone.restapi/actions/runs/13998116091/job/39198164883?pr=1898#step:6:29), in create_or_get
    return dct.setdefault(key, {})
AttributeError: 'str' object has no attribute 'setdefault'

@davisagli
Copy link
Member

davisagli commented Jun 16, 2025

The search endpoint doesn't support expanders. The use of them here suggests that maybe the frontend is trying to call the @search endpoint as a content route when it shouldn't.

The use of unflatten_dotted_dict here is meant for deserializing structured queries like path.depth=1. I'll adjust it to raise a BadRequest instead of an AttributeError if it encounters a key that was already set to a string. On second thought, I'll make it transfer the str value to the "query" key of the new dict, which is what actually makes sense in the context of search queries.

@davisagli davisagli merged commit 910b610 into main Jun 16, 2025
18 of 25 checks passed
@davisagli davisagli deleted the expand_fail branch June 16, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants