workflows: fix external workflow when slug is wrong (#51276)

This commit is contained in:
Lauréline Guérin 2021-02-19 14:22:41 +01:00
parent 5b75505744
commit 2fc2d25d5b
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 21 additions and 1 deletions

View File

@ -6286,6 +6286,23 @@ def test_call_external_workflow_manual_targeting(two_pubs):
logged_error = two_pubs.loggederror_class.select()[0]
assert logged_error.summary == 'Could not find targeted "Data" object by id 421'
# slug not or badly configured
update_action.target_id = '{{ form_var_string }}' # == '1'
update_action.slug = None
wf.store()
perform_items([update_action], formdata)
assert carddef.data_class().get(1).data['bo0'] == '1' # not changed
assert carddef.data_class().get(2).data['bo0'] is None
assert carddef.data_class().get(3).data['bo0'] is None
assert carddef.data_class().get(4).data['bo0'] is None
update_action.slug = 'foo'
wf.store()
perform_items([update_action], formdata)
assert carddef.data_class().get(1).data['bo0'] == '1' # not changed
assert carddef.data_class().get(2).data['bo0'] is None
assert carddef.data_class().get(3).data['bo0'] is None
assert carddef.data_class().get(4).data['bo0'] is None
def test_edit_carddata_with_data_sourced_object(pub):
FormDef.wipe()

View File

@ -48,7 +48,10 @@ class ExternalWorkflowGlobalAction(WorkflowStatusItem):
def get_object_def(self, object_slug=None):
slug = object_slug or self.slug
object_type, slug = slug.split(':')
try:
object_type, slug = slug.split(':')
except (AttributeError, ValueError):
return None
if object_type == 'formdef':
object_class = FormDef
elif object_type == 'carddef':