Skip to content

Commit

Permalink
Do not break slate linkintegrity if block is not a slate block (#1849)
Browse files Browse the repository at this point in the history
* Do not break slate linkintegrity if block is not a slate block

* add changelog

* Update news/1849.bugfix

---------

Co-authored-by: David Glick <[email protected]>
  • Loading branch information
cekk and davisagli authored Dec 17, 2024
1 parent a571899 commit 09c8b01
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/1849.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make slate block linkintegrity checking more robust in case data isn't in the expected format. @cekk
3 changes: 1 addition & 2 deletions src/plone/restapi/blocks_linkintegrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/plone/restapi/deserializer/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 09c8b01

Please sign in to comment.