From f1a8b4729fc57e45982a3a9ce05b5feef410680b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 25 Nov 2016 11:31:17 +0100 Subject: [PATCH] workflows: make sure model filenames are unique (#14096) --- tests/test_workflow_import.py | 11 +++++++++++ wcs/wf/export_to_model.py | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_workflow_import.py b/tests/test_workflow_import.py index e2e9144..34d11b4 100644 --- a/tests/test_workflow_import.py +++ b/tests/test_workflow_import.py @@ -211,6 +211,7 @@ def test_display_form_action(): def test_export_to_model_action(): wf = Workflow(name='status') + wf.store() st1 = wf.add_status('Status1', 'st1') from quixote.http_request import Upload @@ -247,6 +248,16 @@ def test_export_to_model_action(): wf2 = assert_import_export_works(wf) assert wf2.possible_status[0].items[0].model_file.get_file().read() == file_content + wf2 = assert_import_export_works(wf, include_id=True) + wf3 = assert_import_export_works(wf2, include_id=True) + assert wf2.possible_status[0].items[0].model_file.filename == \ + wf3.possible_status[0].items[0].model_file.filename + + wf3 = assert_import_export_works(wf2, include_id=False) + assert wf2.possible_status[0].items[0].model_file.filename != \ + wf3.possible_status[0].items[0].model_file.filename + + def test_export_roles(): wf = Workflow(name='roles') wf.roles = {'foo': 'Bar'} diff --git a/wcs/wf/export_to_model.py b/wcs/wf/export_to_model.py index 257f4d8..6bd93b9 100644 --- a/wcs/wf/export_to_model.py +++ b/wcs/wf/export_to_model.py @@ -19,6 +19,7 @@ import collections from StringIO import StringIO from xml.etree import ElementTree as ET import zipfile +import random import subprocess import tempfile import shutil @@ -458,7 +459,10 @@ class ExportToModel(WorkflowStatusItem): if elem.find('content') is not None: content = elem.find('content').text - ids = (self.parent.parent.id, self.parent.id, self.id) + if self.parent.parent.id: + ids = (self.parent.parent.id, self.parent.id, self.id) + else: + ids = ('i%i' % random.randint(0, 1000000), self.parent.id, self.id) filename = 'export_to_model-%s-%s-%s.upload' % ids upload = Upload(base_filename, content_type) -- 2.10.2