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

Returns an error message when an Invalid occurs when validating a controlpanel field #1771

Merged
merged 6 commits into from Apr 30, 2024

Conversation

wesleybl
Copy link
Member

@wesleybl wesleybl commented Apr 2, 2024

Also translates the message.

Ref: plone/volto#5274

@mister-roboto
Copy link

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

Copy link

netlify bot commented Apr 2, 2024

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit c8adc97
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/66310358e831fc0008d11827

@wesleybl
Copy link
Member Author

wesleybl commented Apr 2, 2024

@jenkins-plone-org please run jobs

When deserializing the controlpanel, do not return the "error" key as an
object, but rather as a string "ValidationError". On the front end, we
are unable to convert an object to json. So we need to return a string.
This is the same way content deserialization does.
@wesleybl
Copy link
Member Author

wesleybl commented Apr 3, 2024

@jenkins-plone-org please run jobs

@davisagli
Copy link
Sponsor Member

@wesleybl Could you add a screenshot of how the error looks now, or give me steps to reproduce it? I can probably figure it out but I'm skimming through a bunch of issues this evening, and it's easier to click "accept" quickly if I can clearly see what the result of the change is.

@wesleybl
Copy link
Member Author

wesleybl commented Apr 4, 2024

@davisagli the steps to reproduce this on the Volto are described in: plone/volto#5274

But this PR here does not make validation errors appear in Volto. It only leaves the compatible restapi response to be displayed in Volto. I'm preparing a PR on Volto to display the errors. But this PR here doesn't "break the screen" if my Volto PR isn't ready. So it's safe to merge first.

With this PR the response with validation error looks like this:

{
  "message": "[{'message': 'Twitter username should not include the \"@\" prefix character.', 'field': 'twitter_username', 'error': 'ValidationError'}]",
  "traceback": [
    "File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 181, in transaction_pubevents",
    "    yield",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 391, in publish_module",
    "    response = _publish(request, new_mod_info)",
    "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 285, in publish",
    "    result = mapply(obj,",
    "             ^^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/mapply.py\", line 98, in mapply",
    "    return debug(object, args, context)",
    "           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 68, in call_object",
    "    return obj(*args)",
    "           ^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/plone.rest-3.0.1-py3.11.egg/plone/rest/service.py\", line 22, in __call__",
    "    return self.render()",
    "           ^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/git/plone.restapi/src/plone/restapi/services/__init__.py\", line 19, in render",
    "    content = self.reply()",
    "              ^^^^^^^^^^^^",
    "",
    "  File \"/home/user/git/plone.restapi/src/plone/restapi/services/controlpanels/update.py\", line 41, in reply",
    "    deserializer()  # The deserializer knows where to put it.",
    "    ^^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/git/plone.restapi/src/plone/restapi/deserializer/controlpanels/__init__.py\", line 89, in __call__",
    "    raise BadRequest(errors)"
  ],
  "type": "BadRequest"
}

@wesleybl
Copy link
Member Author

wesleybl commented Apr 5, 2024

@davisagli I make the Volto PR: plone/volto#5950

Copy link
Member

@nileshgulia1 nileshgulia1 left a comment

Choose a reason for hiding this comment

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

Tested and works fine with plone/volto#5950

@wesleybl
Copy link
Member Author

@jenkins-plone-org please run jobs

@wesleybl
Copy link
Member Author

@tisto @davisagli @sneridagh can you take a look here please?

Copy link
Sponsor Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

Tested in combination with plone/volto#5950, looks good. thanks @wesleybl!

@davisagli
Copy link
Sponsor Member

@jenkins-plone-org please run jobs

@wesleybl wesleybl enabled auto-merge (squash) April 30, 2024 14:42
@wesleybl wesleybl disabled auto-merge April 30, 2024 14:42
@wesleybl
Copy link
Member Author

@jenkins-plone-org please run jobs

@wesleybl wesleybl merged commit 5e989dd into main Apr 30, 2024
25 checks passed
@wesleybl wesleybl deleted the controlpanel_validation branch April 30, 2024 16:02
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.

None yet

4 participants