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

marshmallow_utils: include DynamicSanitizedHTML #191

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

Samk13
Copy link
Member

@Samk13 Samk13 commented Dec 6, 2023

❤️ Thank you for your contribution!

Description

closes #190

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Third-party code

If you've added third-party code (copy/pasted or new dependencies), please reach out to an architect.

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Invenio administration marshmallow utils module."""

from invenio_pages.services.schemas import DynamicSanitizedHTML
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, I would avoid adding a dependency on invenio-pages to invenio-administration.
I think that we should change the code: the part custom_mapping[field_type.inner.__class__]}, should be smarter and first check of the type, then check for the parent classes (to traverse up the inheritance). If not found, than fail.
In this way, it will go up to the parent class and find SanitizedHTML.

WDYT?

Copy link
Member Author

@Samk13 Samk13 Dec 7, 2023

Choose a reason for hiding this comment

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

Done. I implement find_type_in_mapping that locates a specific field type within a given mapping (that is passed as an arg as well) by iterating through its inheritance chain so it will search for the field type in a custom mapping dictionary and returns the corresponding mapped value. If the field type is not found, it raises a KeyError.
Not sure if we should catch the keyError somewhere else?
I created some tests as well. Let me know if you have suggestions for further improvements.

@ntarocco ntarocco merged commit 9811e14 into inveniosoftware:main Dec 7, 2023
6 checks passed
@Samk13 Samk13 deleted the dynamicSanitizedHtml-fix branch December 7, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To release 🔧
Development

Successfully merging this pull request may close these issues.

Marshmallow: Unrecognized Schema Field Error for static pages DynamicSanitizedHTML
2 participants