plone / plone.volto

Plone add-on to configure Plone with Volto, the new default frontend for Plone 6.
https://6.demo.plone.org/
3 stars 3 forks source link

Fix for parent summary serializer when the parent has a but it's empty #148

Closed sneridagh closed 1 month ago

sneridagh commented 1 month ago

I tried it in a project with content (Document) having preview_image_link behavior, and it broke when creating childs because the parent has the empty field, and it tried to access to_object on it.

https://github.com/kitconcept/kitconcept.com/actions/runs/8846612966/job/24369069918?pr=145#step:7:912

"traceback": [
    "File \"/app/lib/python3.11/site-packages/ZPublisher/WSGIPublisher.py\", line 181, in transaction_pubevents",
    "    yield",
    "",
    "  File \"/app/lib/python3.11/site-packages/ZPublisher/WSGIPublisher.py\", line 391, in publish_module",
    "    response = _publish(request, new_mod_info)",
    "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/ZPublisher/WSGIPublisher.py\", line 285, in publish",
    "    result = mapply(obj,",
    "             ^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/ZPublisher/mapply.py\", line 98, in mapply",
    "    return debug(object, args, context)",
    "           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/ZPublisher/WSGIPublisher.py\", line 68, in call_object",
    "    return obj(*args)",
    "           ^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/rest/service.py\", line 21, in __call__",
    "    return self.render()",
    "           ^^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/restapi/services/__init__.py\", line 19, in render",
    "    content = self.reply()",
    "              ^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/restapi/services/content/add.py\", line 115, in reply",
    "    serialized_obj = serializer()",
    "                     ^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/restapi/serializer/dxcontent.py\", line 178, in __call__",
    "    folder_metadata = super().__call__(version=version)",
    "                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/restapi/serializer/dxcontent.py\", line 76, in __call__",
    "    parent_summary = getMultiAdapter(",
    "                     ^^^^^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/restapi/serializer/summary.py\", line 99, in __call__",
    "    value = value()",
    "            ^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/app/contentlisting/realobject.py\", line 113, in image_scales",
    "    return getMultiAdapter((obj, self.request), IImageScalesAdapter)()",
    "           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/Products/CMFPlone/image_scales/adapters.py\", line 30, in __call__",
    "    scales = serializer()",
    "             ^^^^^^^^^^^^",
    "",
    "  File \"/app/lib/python3.11/site-packages/plone/volto/behaviors/preview_link.py\", line 59, in __call__",
    "    linked_image = value.to_object",
    "                   ^^^^^^^^^^^^^^^"
  ],
  "type": "AttributeError"
}

Problem: this is in 6.0.11 :(

Also, changed the order of the condition in the image_field index. Since the most probably is that you change from the default, existing, preview_image to the preview_image_link, is more sane to check the latter first, then the default.

mister-roboto commented 1 month ago

@sneridagh 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!

sneridagh commented 1 month ago

@jenkins-plone-org please run jobs

sneridagh commented 1 month ago

@jenkins-plone-org please run jobs

sneridagh commented 1 month ago

@davisagli ready