From 9accbd728c916fdf374632e40f5d3c112cb39e18 Mon Sep 17 00:00:00 2001 From: stevo Date: Thu, 26 Oct 2023 15:10:35 +0200 Subject: [PATCH 1/2] #114 - fixed FileField json serialization error in train response --- deepaas/api/v2/train.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/deepaas/api/v2/train.py b/deepaas/api/v2/train.py index 29a2074a..2a29be5c 100644 --- a/deepaas/api/v2/train.py +++ b/deepaas/api/v2/train.py @@ -15,6 +15,7 @@ # under the License. import asyncio +import collections from datetime import datetime import uuid @@ -30,6 +31,23 @@ LOG = log.getLogger("deepaas.api.v2.train") +UploadedFileInfo = collections.namedtuple( + "UploadedFileInfo", ("name", "content_type", "original_filename") +) +"""Class to pass the file info returned from build_train_response + +.. py:attribute:: name + + Name of the argument where this file is being sent. + +.. py:attribute:: content_type + + Content-type of the uploaded file + +.. py:attribute:: original_filename + + Filename of the original file being uploaded. +""" def _get_handler(model_name, model_obj): # noqa args = webargs.core.dict2schema(model_obj.get_train_args()) @@ -54,6 +72,15 @@ def build_train_response(uuid, training): ret["args"] = training["args"] ret["uuid"] = uuid + for (key, val) in ret["args"].items(): + if isinstance(val, web.FileField): + aux = UploadedFileInfo( + name=val.name, + content_type=val.content_type, + original_filename=val.filename, + ) + ret['args'][key] = aux + if training["task"].cancelled(): ret["status"] = "cancelled" elif training["task"].done(): From d430de137762f59604d3c14521644a4b9ec83da1 Mon Sep 17 00:00:00 2001 From: stevo Date: Fri, 27 Oct 2023 12:46:23 +0200 Subject: [PATCH 2/2] #144 - formatted code by black --- deepaas/api/v2/train.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deepaas/api/v2/train.py b/deepaas/api/v2/train.py index 2a29be5c..ca709c60 100644 --- a/deepaas/api/v2/train.py +++ b/deepaas/api/v2/train.py @@ -49,6 +49,7 @@ Filename of the original file being uploaded. """ + def _get_handler(model_name, model_obj): # noqa args = webargs.core.dict2schema(model_obj.get_train_args()) args.opts.ordered = True @@ -72,14 +73,14 @@ def build_train_response(uuid, training): ret["args"] = training["args"] ret["uuid"] = uuid - for (key, val) in ret["args"].items(): + for key, val in ret["args"].items(): if isinstance(val, web.FileField): aux = UploadedFileInfo( name=val.name, content_type=val.content_type, original_filename=val.filename, ) - ret['args'][key] = aux + ret["args"][key] = aux if training["task"].cancelled(): ret["status"] = "cancelled"