From 7cfccf2f3872c49b55417eaeeb0a5e8fd434b89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 20 May 2016 09:40:11 +0200 Subject: [PATCH 1/2] misc: fix serialization of PicklableUpload imported from qommon (#11000) --- tests/test_api.py | 6 +++++- wcs/qommon/misc.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 3cdacd6..9dd91e1 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -874,7 +874,10 @@ def test_formdata_with_workflow_data(pub, local_user): upload = PicklableUpload('test.txt', 'text/plain', 'ascii') upload.receive(['test']) - formdata.workflow_data = {'blah': upload, 'xxx': 23} + from qommon.form import PicklableUpload as PicklableUpload2 + upload2 = PicklableUpload2('test.txt', 'text/plain', 'ascii') + upload2.receive(['test']) + formdata.workflow_data = {'blah': upload, 'blah2': upload2, 'xxx': 23} formdata.store() resp = get_app(pub).get( @@ -883,6 +886,7 @@ def test_formdata_with_workflow_data(pub, local_user): assert resp.json['workflow']['data']['blah']['filename'] == 'test.txt' assert resp.json['workflow']['data']['blah']['content_type'] == 'text/plain' assert base64.decodestring(resp.json['workflow']['data']['blah']['content']) == 'test' + assert base64.decodestring(resp.json['workflow']['data']['blah2']['content']) == 'test' def test_user_by_nameid(pub, local_user): resp = get_app(pub).get(sign_uri('/api/users/xyz/', user=local_user), diff --git a/wcs/qommon/misc.py b/wcs/qommon/misc.py index 0ff18d3..1454afe 100644 --- a/wcs/qommon/misc.py +++ b/wcs/qommon/misc.py @@ -428,8 +428,13 @@ class JSONEncoder(json.JSONEncoder): if isinstance(obj, time.struct_time): return datetime.datetime.utcfromtimestamp(time.mktime(obj)).isoformat() + 'Z' - from .form import PicklableUpload - if isinstance(obj, PicklableUpload): + # PicklableUpload may be known as qommon.form.PicklableUpload or + # wcs.qommon.form.PicklableUpload and considered different classes + # by Python. It shouldn't have to be that way but workaround that + # and check for both classes. + from qommon.form import PicklableUpload + from wcs.qommon.form import PicklableUpload as PicklableUpload2 + if isinstance(obj, PicklableUpload) or isinstance(obj, PicklableUpload2): return { 'filename': obj.base_filename, 'content_type': obj.content_type or 'application/octet-stream', -- 2.8.1