diff --git a/news/1849.bugfix b/news/1849.bugfix new file mode 100644 index 000000000..29cc13e7c --- /dev/null +++ b/news/1849.bugfix @@ -0,0 +1 @@ +Make slate block linkintegrity checking more robust in case data isn't in the expected format. @cekk diff --git a/src/plone/restapi/blocks_linkintegrity.py b/src/plone/restapi/blocks_linkintegrity.py index 754f5c256..dc5343ff1 100644 --- a/src/plone/restapi/blocks_linkintegrity.py +++ b/src/plone/restapi/blocks_linkintegrity.py @@ -69,9 +69,8 @@ def __init__(self, context, request): def __call__(self, block): value = (block or {}).get(self.field, []) children = iterate_children(value or []) - for child in children: - node_type = child.get("type") + node_type = child.get("type", "") if node_type: handler = getattr(self, f"handle_{node_type}", None) if handler: diff --git a/src/plone/restapi/deserializer/blocks.py b/src/plone/restapi/deserializer/blocks.py index 59e26a807..e4a8f825b 100644 --- a/src/plone/restapi/deserializer/blocks.py +++ b/src/plone/restapi/deserializer/blocks.py @@ -24,9 +24,10 @@ def iterate_children(value): queue = deque(value) while queue: child = queue.pop() - yield child - if child.get("children"): - queue.extend(child["children"] or []) + if isinstance(child, dict): + yield child + if child.get("children", []): + queue.extend(child["children"] or []) @implementer(IFieldDeserializer)