Skip to content
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

In @vocabulary endpoint, call the vocabulary factory with the 'title'… #1807

Closed
wants to merge 3 commits into from

Conversation

tiberiuichim
Copy link
Contributor

@tiberiuichim tiberiuichim commented Sep 4, 2024

… field from the request form

Fixes #1806


📚 Documentation preview 📚: https://plonerestapi--1807.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!

@@ -86,7 +86,8 @@ def reply(self):
404, "Not Found", f"The vocabulary '{vocabulary_name}' does not exist"
)

vocabulary = factory(self.context)
query = self.request.form.get("title", "")
vocabulary = factory(self.context, query=query)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiberiuichim This won't work with many vocabularies, which is why a lot of tests broke.

The IVocabularyFactory interface specifies that a vocab factory is called with a context, but not other parameters: https://github.com/zopefoundation/zope.schema/blob/master/src/zope/schema/interfaces.py#L1087

The addition of the query parameter seems to be something that was made up for the vocabulary factories in plone.app.vocabularies.principals without following any formal interface. This makes it hard to detect here how the factory is supposed to be called.

To really sort this out, we need to define a new interface like IQueryableVocabularyFactory. Then plone.app.vocabularies can define that these vocabulary factories implement that interface, and plone.restapi can be updated to pass the query to factories which provide that interface.

@tiberiuichim
Copy link
Contributor Author

tiberiuichim commented Sep 5, 2024

@davisagli what's your feeling on the low-tech approach, only pass the query parameter if it exists in the request?

With this change I can use the SelectAutocomplete widget to search and select users. I can understand your feeling about "use a custom endpoint", but it would be a lot more work than just these 3 changed lines, which are legitimate in filling a gap in Plone - Volto compatibility.

Low-tech approach doesn't work.

@davisagli
Copy link
Member

what's your feeling on the low-tech approach, only pass the query parameter if it exists in the request?

Is there some mechanism to make sure that it is only sent in the request for the vocabularies that support it?

@tiberiuichim
Copy link
Contributor Author

No, the simple guard doesn't work, we have to implement your approach. I was hoping to limit the "damage" to plone.app.restapi, but it looks like it will need work in plone.app.vocabularies as well

@davisagli
Copy link
Member

@tiberiuichim My approach is probably possible to do in plone.restapi only, if it imports and applies a custom interface to these vocabularies at import time, and checks for it at runtime.

@tiberiuichim
Copy link
Contributor Author

I'll try a different approach. I'll implement my own custom vocabulary, based on the p.a.v.Principals, which would properly use the serializer API approach in plone.restapi. This would mean that this PR wouldn't be needed anymore

@davisagli
Copy link
Member

@tiberiuichim Okay, I'll close this for now

@davisagli davisagli closed this Sep 5, 2024
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.

Vocabularies should be called with query, if it exists
3 participants