From 4f3dc60311825db0a68ebfa9cc2956bded7233ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 19 Nov 2019 09:35:08 +0100 Subject: [PATCH] formdef: add pre-json serialization of struct_time workflow options (#36515) (python3 json serializer would otherwise catch them and serialize them as tuples) --- tests/test_formdef.py | 4 ++-- wcs/formdef.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_formdef.py b/tests/test_formdef.py index 289a3a3ba..e475875a6 100644 --- a/tests/test_formdef.py +++ b/tests/test_formdef.py @@ -160,8 +160,8 @@ def test_schema_with_date_variable(pub): DateField(label='Test', type='date', varname='foo')) wf.store() formdef.workflow_id = wf.id - formdef.workflow_options = {'foo': time.gmtime(time.mktime((2016, 4, 2, 0, 0, 0, 0, 0, 0)))} - assert json.loads(formdef.export_to_json())['options']['foo'].startswith('2016-04') + formdef.workflow_options = {'foo': datetime.datetime(2016, 4, 2).timetuple()} + assert json.loads(formdef.export_to_json())['options']['foo'].startswith('2016-04-02') def test_substitution_variables_object(pub): formdef = FormDef() diff --git a/wcs/formdef.py b/wcs/formdef.py index 694e4d031..eaad83cb5 100644 --- a/wcs/formdef.py +++ b/wcs/formdef.py @@ -765,7 +765,12 @@ class FormDef(StorableObject): root['geolocations'] = self.geolocations.copy() if self.workflow_options: - root['options'] = self.workflow_options + root['options'] = self.workflow_options.copy() + for k, v in list(root['options'].items()): + # convert time.struct_time to strings as python3 would + # serialize it as tuple. + if isinstance(v, time.struct_time): + root['options'][k] = time.strftime('%Y-%m-%dT%H:%M:%S', v) if self.required_authentication_contexts: root['required_authentication_contexts'] = self.required_authentication_contexts[:]