From da544affae857c7d12734b39e352541736956bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 24 Jun 2017 12:21:46 +0200 Subject: [PATCH] workflows: don't try substituting images with non-images (#17174) --- tests/test_workflows.py | 15 +++++++++++++++ wcs/wf/export_to_model.py | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 0bc28bc8..41a8dc32 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -1931,6 +1931,21 @@ def test_export_to_model_image(pub): # check the image has been replaced by the one from the formdata assert zinfo.file_size == len(image_data) + # check with missing data or wrong kind of data + for field_value in (None, 'wrong kind'): + formdata = formdef.data_class()() + formdata.data = {'3': field_value} + formdata.just_created() + formdata.store() + pub.substitutions.feed(formdata) + + item.perform(formdata) + + zfile = zipfile.ZipFile(formdata.evolution[-1].parts[0].filename, mode='r') + zinfo = zfile.getinfo('Pictures/10000000000000320000003276E9D46581B55C88.jpg') + # check the original image has been left + assert zinfo.file_size == 580 + def test_global_timeouts(pub): FormDef.wipe() Workflow.wipe() diff --git a/wcs/wf/export_to_model.py b/wcs/wf/export_to_model.py index a9d11145..3de404e8 100644 --- a/wcs/wf/export_to_model.py +++ b/wcs/wf/export_to_model.py @@ -436,6 +436,8 @@ class ExportToModel(WorkflowStatusItem): variable_image = self.compute(name) except: continue + if not hasattr(variable_image, 'get_content'): + continue image = [x for x in node.getchildren() if x.tag == DRAW_IMAGE][0] new_images[image.attrib.get(XLINK_HREF)] = variable_image -- 2.13.1