Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip broken catalog brains in WorkflowSecurityUpdater. #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Changelog
2.12.1 (unreleased)
-------------------

- Nothing changed yet.

- Skip broken catalog brains in WorkflowSecurityUpdater. [phgross]

2.12.0 (2018-07-26)
-------------------
Expand Down
21 changes: 21 additions & 0 deletions ftw/upgrade/tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from Acquisition import aq_inner
from Acquisition import aq_parent
from ftw.builder import Builder
from ftw.builder import create
from ftw.upgrade.placefulworkflow import PlacefulWorkflowPolicyActivator
Expand Down Expand Up @@ -259,3 +261,22 @@ def test_respects_placeful_workflows_when_updating(self):
self.assert_permission_not_acquired(
'View', document,
'The document should have been updated but was not.')

def test_skip_broken_brains(self):
self.set_workflow_chain(for_type='Folder',
to_workflow='folder_workflow')

folder1 = create(Builder('folder'))
folder2 = create(Builder('folder'))
folder3 = create(Builder('folder'))

# Delete folder and suppress events so that the catalog does not notice
# the object is gone, then try to get the object.
aq_parent(aq_inner(folder2))._delObject(folder2.getId(),
suppress_events=True)

updater = WorkflowSecurityUpdater()
generator = updater.lookup_objects('Folder')

self.assertEquals([folder1, folder3],
[obj for obj in generator])
10 changes: 8 additions & 2 deletions ftw/upgrade/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ def lookup_objects(self, types):
query = {'portal_type': types}
brains = tuple(catalog.unrestrictedSearchResults(query))

lookup = lambda brain: portal.unrestrictedTraverse(brain.getPath())
generator = SizedGenerator((lookup(brain) for brain in brains),
def lookup(brain):
try:
return portal.unrestrictedTraverse(brain.getPath())
except KeyError:
return None

generator = (lookup(brain) for brain in brains)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see two problems here:

  1. We are not uncataloging missing objects.
  2. This line does not filter None elements, so the length of the SizedGenerator in the next line is too big when there are broken brains.

Could we move catalog_unrestricted_get_object from the step class into a place where we can reuse it here, so that we can use the same code?
I'd then use the same code as in #146:

generator = (self.catalog_unrestricted_get_object(brain) for brain in brains)
generator = (obj for obj in generator if obj is not None)
return SizedGenerator(generator, len(brains))

generator = SizedGenerator((obj for obj in generator if obj),
len(brains))
return ProgressLogger('Update object security', generator)

Expand Down