Skip to content

Commit

Permalink
Dexterity deserializer: Allow to ignore validation errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Dec 4, 2024
1 parent 447a87c commit 40a399f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/plone/restapi/deserializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
from zope.schema.interfaces import ValidationError
from zope.security.interfaces import IPermission

import logging


logger = logging.getLogger(__name__)


@implementer(IDeserializeFromJson)
@adapter(IDexterityContent, Interface)
Expand All @@ -37,7 +42,12 @@ def __init__(self, context, request):
self.modified = {}

def __call__(
self, validate_all=False, data=None, create=False, mask_validation_errors=True
self,
validate_all=False,
data=None,
create=False,
mask_validation_errors=True,
ignore_errors=False,
): # noqa: ignore=C901

if data is None:
Expand All @@ -61,7 +71,10 @@ def __call__(
error["error"] = "ValidationError"
for error in errors:
error["message"] = translate(error["message"], context=self.request)
raise BadRequest(errors)
if ignore_errors:
logger.warn("Ignoring validation errors: %s", errors)
else:
raise BadRequest(errors)

# We'll set the layout after the validation and even if there
# are no other changes.
Expand Down

0 comments on commit 40a399f

Please sign in to comment.