Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#114 - fixed FileField json serialization error in train response #124

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions deepaas/api/v2/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# under the License.

import asyncio
import collections
from datetime import datetime
import uuid

Expand All @@ -30,6 +31,24 @@

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())
Expand All @@ -54,6 +73,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():
Expand Down