From 09c8b018153a7208ca225c1e729501f2fc8f2c99 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 17 Dec 2024 06:26:21 +0100 Subject: [PATCH] Do not break slate linkintegrity if block is not a slate block (#1849) * Do not break slate linkintegrity if block is not a slate block * add changelog * Update news/1849.bugfix --------- Co-authored-by: David Glick --- news/1849.bugfix | 1 + src/plone/restapi/blocks_linkintegrity.py | 3 +-- src/plone/restapi/deserializer/blocks.py | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 news/1849.bugfix diff --git a/news/1849.bugfix b/news/1849.bugfix new file mode 100644 index 0000000000..29cc13e7c0 --- /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 754f5c256b..dc5343ff1d 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 59e26a807c..e4a8f825be 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)