From 9c5d4f2c26a7d4979a61e0b749772f7babb708ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 1 Nov 2016 15:50:47 +0100 Subject: [PATCH 2/2] fields: don't crash exporting incomplete post-condition (#13815) --- tests/test_formdef_import.py | 11 +++++++++++ wcs/fields.py | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_formdef_import.py b/tests/test_formdef_import.py index 5ecb046..9858369 100644 --- a/tests/test_formdef_import.py +++ b/tests/test_formdef_import.py @@ -310,6 +310,17 @@ def test_page_post_conditions(): assert fd2.fields[0].type == 'page' assert fd2.fields[0].post_conditions == formdef.fields[0].post_conditions + # test incomplete post condition (not allowed anymore but old formdefs may + # have this) + formdef.fields = [ + fields.PageField(id='1', type='page', + post_conditions=[{'condition': 'blah', 'error_message': None}]), + ] + formdef_xml = formdef.export_to_xml(include_id=True) + fd2 = FormDef.import_from_xml_tree(formdef_xml, include_id=True) + assert fd2.fields[0].post_conditions[0]['condition'] == 'blah' + assert fd2.fields[0].post_conditions[0]['error_message'] == '' + def test_workflow_roles(): Role.wipe() role = Role(name='blah') diff --git a/wcs/fields.py b/wcs/fields.py index dd9a8bf..4bd8fc1 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -1463,9 +1463,9 @@ class PageField(Field): for post_condition in self.post_conditions: condition_node = ET.SubElement(conditions_node, 'post_condition') ET.SubElement(condition_node, 'condition').text = unicode( - post_condition['condition'], charset, 'replace') + post_condition['condition'] or '', charset, 'replace') ET.SubElement(condition_node, 'error_message').text = unicode( - post_condition['error_message'], charset, 'replace') + post_condition['error_message'] or '', charset, 'replace') def fill_admin_form(self, form): form.add(StringWidget, 'label', title = _('Label'), value = self.label, -- 2.10.2