ai4os / DEEPaaS

A REST API to serve machine learning and deep learning models
https://deepaas.readthedocs.io
Apache License 2.0
35 stars 15 forks source link

`POST /v2/models/{model}` raises `FileField is not JSON serializable` with file argumetns #114

Closed BorjaEst closed 7 months ago

BorjaEst commented 1 year ago

Description

Error in train when implementing file arguments in get_train_args: ERROR aiohttp.server TypeError: Object of type FileField is not JSON serializable

Steps to Reproduce

  1. Download demo_app (or any other use case).
  2. Add a file type into get_train_args:
    def get_train_args():
    arg_dict = {
        "demo-image": fields.Field(
            required=True,
            type="file",
            location="form",
            description="image",
        ),
    }
    return arg_dict
  3. Run deepaas: deepaas-run ...
  4. Call train method providing a dummy txt or any other file.

Expected behavior:

Get the file as argument on train function (as in predict).

Actual behavior

2023-05-24 11:57:55.606 14073 INFO aiohttp.access [-] 127.0.0.1 [24/May/2023:09:57:55 +0000] "GET /swagger.json HTTP/1.1" 200 11513 "http://127.0.0.1:5000/ui" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server [-] Error handling request: TypeError: Object of type FileField is not JSON serializable
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server Traceback (most recent call last):
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     resp = await request_handler(request)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     resp = await handler(request)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return await handler(request)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 108, in impl
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return await handler(request)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return await handler(request)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/webargs/asyncparser.py", line 157, in wrapper
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return await func(*new_args, **kwargs)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/deepaas/api/v2/train.py", line 91, in post
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return web.json_response(ret)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages/aiohttp/web_response.py", line 817, in json_response
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     text = dumps(data)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/json/__init__.py", line 231, in dumps
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return _default_encoder.encode(obj)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/json/encoder.py", line 199, in encode
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     chunks = self.iterencode(o, _one_shot=True)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/json/encoder.py", line 257, in iterencode
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     return _iterencode(o, 0)
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server   File "/home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/json/encoder.py", line 179, in default
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server     raise TypeError(f'Object of type {o.__class__.__name__} '
2023-05-24 11:58:02.030 14073 ERROR aiohttp.server TypeError: Object of type FileField is not JSON serializable

Versions

$ pip show deepaas
Name: deepaas
Version: 2.1.0
Summary: DEEPaaS is a REST API to expose a machine learning model.
Home-page: https://github.com/indigo-dc/deepaas
...
License: Apache-2
Location: /home/borja/miniconda3/envs/DEEPaaS/lib/python3.10/site-packages
Requires: aiohttp, aiohttp-apispec, jsonschema, marshmallow, oslo.config, oslo.log, pbr, six, stevedore, webargs, werkzeug
Required-by: demo-app