Skip to content

Commit

Permalink
Fix error in viewlet when related dexterity item has been deleted.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Jan 13, 2017
1 parent bd2a327 commit 15156a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions plone/app/layout/viewlets/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
18 changes: 18 additions & 0 deletions plone/app/layout/viewlets/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 15156a4

Please sign in to comment.