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

Provide IJsonCompatible adapter for RichTextValue objects #1583

Open
erral opened this issue Feb 13, 2023 · 1 comment · May be fixed by #1584
Open

Provide IJsonCompatible adapter for RichTextValue objects #1583

erral opened this issue Feb 13, 2023 · 1 comment · May be fixed by #1584

Comments

@erral
Copy link
Member

erral commented Feb 13, 2023

When defining a default value in a RichText field, this value needs to be passed through a IJsonCompatible adapter, but we are missing the converter for RichTextValue objects, and thus the edit form rendering breaks in Volto.

Dexterity object definition:

    download_full_dataset_text = RichText(
        title=_(
            'Text of the "Download full dataset entry',
        ),
        description=_(
            "Enter the text that will be shown in the Download tab",
        ),
        default=(
            "<p>If you want to download the full dataset, click <a"
            ' href="/en/how-to-guides/how-to-download-spatial-data/how-to-download-m2m">here</a>'
            " to learn more.</p>"
        ),
        required=False,
        readonly=False,
    )

plone.restapi fail when rendering the Volto edit form:

2023-02-13 17:05:44,536 ERROR   [Zope.SiteErrorLog:22][waitress-1] TypeError: http://localhost:3000/en/@types/DataSet
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 371, in publish_module
  Module ZPublisher.WSGIPublisher, line 266, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module plone.rest.service, line 22, in __call__
  Module plone.restapi.services, line 19, in render
  Module plone.restapi.services.types.get, line 114, in reply
  Module plone.restapi.services.types.get, line 136, in reply_for_type
  Module plone.restapi.types.utils, line 329, in get_info_for_type
  Module plone.restapi.types.utils, line 272, in get_jsonschema_for_portal_type
  Module plone.restapi.types.utils, line 261, in get_jsonschema_for_fti
  Module zope.component.hooks, line 135, in adapter_hook
  Module plone.restapi.serializer.converters, line 136, in dict_converter
  Module plone.restapi.serializer.converters, line 68, in json_compatible
  Module zope.component.hooks, line 135, in adapter_hook
  Module plone.restapi.serializer.converters, line 136, in dict_converter
  Module plone.restapi.serializer.converters, line 68, in json_compatible
  Module zope.component.hooks, line 135, in adapter_hook
  Module plone.restapi.serializer.converters, line 80, in default_converter
TypeError: No converter for making RichTextValue object. (Did you mean <attribute>.raw or <attribute>.output?) (<class 'plone.app.textfield.value.RichTextValue'>) JSON compatible.
@davisagli
Copy link
Member

The problem is a bit more subtle.

There is already an IJsonCompatible adapter for RichTextValue: https://github.com/plone/plone.restapi/blob/master/src/plone/restapi/serializer/converters.py#L178

It is even documented: https://6.docs.plone.org/plone.restapi/docs/source/usage/serialization.html#richtext-fields

The problem is that it is a converter which requires a context (in order to resolve any relative links within HTML rich text, IIRC). And in this traceback, the object being serialized is a default value in a type schema, so there is no context.

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 a pull request may close this issue.

2 participants