From 15156a4e7970bce7cf47351c29dab63dad0d1eaa Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 13 Jan 2017 14:21:51 +0100 Subject: [PATCH] Fix error in viewlet when related dexterity item has been deleted. --- CHANGES.rst | 3 ++- plone/app/layout/viewlets/content.py | 4 ++++ .../app/layout/viewlets/tests/test_content.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index a53be638..52f8f9b5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +14,8 @@ New features: Bug fixes: -- *add item here* +- Fix error in viewlet when related dexterity item has been deleted. + [maurits] 2.3.16 (2016-12-19) diff --git a/plone/app/layout/viewlets/content.py b/plone/app/layout/viewlets/content.py index 83b8c928..78929976 100644 --- a/plone/app/layout/viewlets/content.py +++ b/plone/app/layout/viewlets/content.py @@ -176,6 +176,10 @@ def related2brains(self, related): brains = [] for r in related: path = r.to_path + if path is None: + # Item was deleted. The related item should have been cleaned + # up, but apparently this does not happen. + continue # the query will return an empty list if the user has no # permission to see the target object brains.extend(catalog(path=dict(query=path, depth=0))) diff --git a/plone/app/layout/viewlets/tests/test_content.py b/plone/app/layout/viewlets/tests/test_content.py index 3bf71bc1..04b3f586 100644 --- a/plone/app/layout/viewlets/tests/test_content.py +++ b/plone/app/layout/viewlets/tests/test_content.py @@ -106,6 +106,15 @@ def testRelatedItems(self): related = viewlet.related_items() self.assertEqual([x.Title for x in related], ['Document 2', 'Document 3']) + def testDeletedRelatedItems(self): + # Deleted related items should not cause problems. + self.folder._delObject('doc2') + request = self.app.REQUEST + viewlet = ContentRelatedItems(self.folder.doc1, request, None, None) + viewlet.update() + related = viewlet.related_items() + self.assertEqual([x.Title for x in related], ['Document 3']) + class TestDexterityRelatedItemsViewlet(ViewletsTestCase): @@ -174,6 +183,15 @@ def testDexterityFolderRelatedItems(self): related = viewlet.related_items() self.assertEqual(len(related), 1) + def testDexterityDeletedRelatedItems(self): + # Deleted related items should not cause problems. + self.folder._delObject('doc1') + request = self.app.REQUEST + viewlet = ContentRelatedItems(self.folder.dex1, request, None, None) + viewlet.update() + related = viewlet.related_items() + self.assertEqual([x.id for x in related], ['doc2']) + def test_suite(): from unittest import defaultTestLoader